OAuthAuthenticator
public class OAuthAuthenticator : Authenticator
An OAuth based authentication strategy for authenticating a user on Cisco Webex.
Since
1.2.0-
See
See Authenticator.authorizedSince
1.2.0Declaration
Swift
public var authorized: Bool { get }
-
Creates a new OAuth authentication strategy
OAuthAuthenticator
- This should be used when the SDK is to be authenticated as a registered user to Cisco Webex cloud.
Note
If MDM profile is installed on the device, then
isFedRAMPEnvironment
property will be overriden by the value from the profile.Since
1.2.0
let clientId = "Def123456..." let clientSecret = "fed456..." let scope = "spark:all meeting:schedules_write" let redirectUri = "MyCustomApplication://response" let emailId = "user@example.com" let authenticator = OAuthAuthenticator(clientId: clientId, clientSecret: clientSecret, scope: scope, redirectUri: redirectUri, emailId: emailId) let webex = Webex(authenticator: authenticator) ... authenticator.authorize(parentViewController: self) { success in if !success { print("User not authorized") } }
Declaration
Swift
public convenience init(clientId: String, clientSecret: String, scope: String = "spark:all", redirectUri: String, emailId: String, isFedRAMPEnvironment: Bool = false)
Parameters
clientId
The OAuth client id
clientSecret
The OAuth client secret
scope
Space separated list of any additional scopes that your access token should have. Note:
spark:all
scope should be always provided. Please contact support if you want to add new scopes to your app.redirectUri
The redirect URI that will be called when completing the authentication. This must match the redirect URI registered to your clientId.
emailId
The email address of the webex user.
isFedRAMPEnvironment
To activate the FedRAMP environment, you need to pass this value as true. By default, it’s false. Note that switching between the FedRAMP and the Commercial environment is only possible before logging in, and any changes made to this value after a successful login will result in login failure.
-
Brings up a web-based authorization view controller and directs the user through the OAuth process
Declaration
Swift
public func authorize(parentViewController: UIViewController, completionHandler: ((_ result: OAuthResult) -> Void)?)
Parameters
parentViewController
The parent view controller for the OAuth view controller
completionHandler
The completion handler will be called when authentication is complete, with a
OAuthResult
to indicate if the authentication process was successful. It will be called directly after the OAuth view controller has begun to dismiss itself in an animated way.Return Value
Void
-
Handles fetching the access token using the OAuth code generated during authorization. Assumes the application handles the authentication part of the process itself.
Since
2.6.0Declaration
Swift
public func authorize(oauthCode: String, completionHandler: ((_ result: OAuthResult) -> Void)? = nil)
Parameters
code
the OAuth code generated during authorization.
completionHandler
the completion handler will be called when fetching the access token is complete, with a boolean to indicate if the process was successful.
-
Returns an access token of this
Authenticator
.This may involve long-running operations such as service calls, but may also return immediately. The application should not make assumptions about how quickly this completes. If the access token could not be retrieved then the completion handler will be called with nil.
Since
1.2.0Declaration
Swift
public func accessToken(completionHandler: @escaping (_ accessToken: Result<String>) -> Void)
Parameters
completionHandler
a closure to be executed when completed, with the access token if successfully retrieved, otherwise nil.
-
Deauthorizes the current user and clears any persistent state with regards to the current user. After this method has been invoked, for continued usage, new instances of
OAuthAuthenticator
andWebex
need to be created and usedSince
1.2.0Declaration
Swift
public func deauthorize(completionHandler: (() -> Void)?)
-
Provides an authorization url that can used for first leg of OAuth2
Since
3.1.0Declaration
Swift
public func getAuthorizationUrl(completionHandler: @escaping (OAuthResult, URL?) -> Void)
Parameters
completionHandler
the completion handler will be called when fetching the authorizationUrl is complete, with a OAuthResult and the authorization URL to indicate if the process was successful.