Link the CloudSDK.framework with your project as Embedded Binary
.
To authenticate with PACE via OAuth provide the following information to Cloud SDK:
- clientId
- redirectUrl
- scope
let authRequest = AuthorizationRequest(clientId: "ABC",
redirectUrl: "CloudSDK://oauth",
scope: "read")
CloudSDK.shared.createSession(for: authRequest, needsAuthentication: { webview in
// adjust the style of the webview by setting tintColor and barTintColor
// present the webview in your app so the user can log in and grant authorization to your app
}, authenticated: { token in
// dismiss the webview
// user granted authorization, continue with your requests
}, failure: { error in
// dismiss the webview
// user cancelled the authorization or an error occurred
})
Once your app is authenticated, you can access the users information:
CloudSDK.shared.getUserInfo(completion: { user in
// handle user information
}, failure: { (error, statusCode) in
// an error occurred
})
Once your app is authenticated, you can perform authenticated requests with the PACE backend. Requests to an URL other than the PACE API are rejected.
let request = URLRequest(url: url)
CloudSDK.shared.perform(request: request) { (data, response, error) in
// handle response
}
CloudSDK.shared.hasValidSession { hasValidSession in
// sessions are renewed automatically by CloudSDK
// if the session is invalid you may need to authenticate again
}
CloudSDK.shared.getSessionToken { sessionToken in
// nil if no session exists or token is invalid
}
You can logout and remove the session from the keychain:
CloudSDK.shared.logout()