SFOAuthCoordinator Class Reference

Inherits from NSObject
Conforms to WKNavigationDelegate
WKUIDelegate
Declared in SFOAuthCoordinator.h

Overview

The SFOAuthCoordinator class is the central class of the OAuth2 authentication process.

This class manages a WKWebView instance and monitors it as it works its way through the various stages of the OAuth2 workflow. When authentication is complete, the coordinator instance extracts the necessary session information from the response and updates the SFOAuthCredentials object as necessary.

Warning: This class requires the following dependencies: the Security framework and either the NSJSONSerialization iOS 5.0 SDK class or the third party SBJsonParser class.

Other Methods

  credentials

User credentials to use within the authentication process.

@property (nonatomic, strong, nullable) SFOAuthCredentials *credentials

Discussion

Warning: The behavior of this class is undefined if this property is set after authenticate has been called and authentication has started.

Warning: This property must not be nil at the time the authenticate method is called or an exception will be raised.

Declared In

SFOAuthCoordinator.h

  delegate

The delegate object for this coordinator.

@property (nonatomic, weak) id<SFOAuthCoordinatorDelegate> delegate

Discussion

The delegate is sent messages at different stages of the authentication process.

Declared In

SFOAuthCoordinator.h

  scopes

A set of scopes for OAuth. See: https://help.salesforce.com/apex/HTViewHelpDoc?language=en&id=remoteaccess_oauth_scopes.htm

@property (nonatomic, copy, nullable) NSSet *scopes

Discussion

Generally you need not specify this unless you are using something other than the “api” scope. For instance, if you are accessing Visualforce pages as well as the REST API, you could use: [@“api”, @“visualforce”]

(You need not specify the “refresh_token” scope as this is always requested by this library.)

If you do not set this property, the library does not add the “scope” parameter to the initial OAuth request, which implicitly sets the scope to include: “id”, “api”, and “refresh_token”.

Declared In

SFOAuthCoordinator.h

  timeout

Timeout interval for OAuth requests.

@property (nonatomic, assign) NSTimeInterval timeout

Discussion

This value controls how long requests will wait before timing out.

Declared In

SFOAuthCoordinator.h

  view

View in which the user will input OAuth credentials for the user-agent flow OAuth process.

@property (nonatomic, readonly, null_unspecified) WKWebView *view

Discussion

This is only guaranteed to be non-nil after one of the delegate methods returning a web view has been called.

Declared In

SFOAuthCoordinator.h

  asWebAuthenticationSession

Auth session through which the user will input OAuth credentials for the user-agent flow OAuth process.

@property (nonatomic, readonly, null_unspecified) ASWebAuthenticationSession *asWebAuthenticationSession

Declared In

SFOAuthCoordinator.h

  userAgentForAuth

The user agent string that will be used for authentication. While this property will persist throughout the lifetime of the coordinator object, the user agent configured for the system will be reset back to its original value in between authentication requests.

@property (nonatomic, copy) NSString *userAgentForAuth

Declared In

SFOAuthCoordinator.h

  additionalOAuthParameterKeys

An array of additional keys (NSString) to parse during OAuth

@property (nonatomic, strong) NSArray *additionalOAuthParameterKeys

Declared In

SFOAuthCoordinator.h

  additionalTokenRefreshParams

A dictionary of additional parameters (key value pairs) to send during token refresh

@property (nonatomic, strong) NSDictionary *additionalTokenRefreshParams

Declared In

SFOAuthCoordinator.h

  brandLoginPath

Brand Login Path. The brand login path used for the authorize endpoint e.g. /brand in https://community.force.com/services/oauth2/authorize/?response_type=code&…

@property (nonatomic, copy) NSString *brandLoginPath

Declared In

SFOAuthCoordinator.h

  useBrowserAuth

Setup the coordinator to use ASWebAuthenticationSession for authentication.

@property (nonatomic, assign) BOOL useBrowserAuth

Declared In

SFOAuthCoordinator.h

  authClient

@property (nonatomic, strong) id<SFSDKOAuthProtocol> authClient

  useNativeAuth

Setup the coordinator to use an app provided native UI for authentication.

@property (nonatomic, assign) BOOL useNativeAuth

Declared In

SFOAuthCoordinator.h

Initialization

– initWithCredentials:

Initializes a new OAuth coordinator with the supplied credentials. This is the designated initializer.

- (id)initWithCredentials:(null_unspecified SFOAuthCredentials *)credentials

Parameters

credentials

An instance of SFOAuthCredentials identifying the user to be authenticated.

Return Value

The initialized authentication coordinator.

Discussion

Warning: Although it is permissible to pass nil for the credentials argument, the credentials propery must not be nil prior to calling the authenticate method or an exception will be raised.

Declared In

SFOAuthCoordinator.h

Authentication control

– authenticate

Begins the authentication process.

- (void)authenticate

Exceptions

NSInternalInconsistencyException

If called when the credentials property is nil.

Declared In

SFOAuthCoordinator.h

– authenticateWithCredentials:

Sets the credentials property and begins the authentication process. Simply a convenience method for: coordinator.credentials = theCredentials; [coordinator authenticate];

- (void)authenticateWithCredentials:(SFOAuthCredentials *)credentials

Parameters

credentials

The OAuth credentials used for authentication.

Exceptions

NSInternalInconsistencyException

If called with a nil credentials argument.

Declared In

SFOAuthCoordinator.h

– isAuthenticating

Returns YES if the coordinator is in the process of authentication; otherwise NO.

- (BOOL)isAuthenticating

Declared In

SFOAuthCoordinator.h

– stopAuthentication

Stops the authentication process.

- (void)stopAuthentication

Declared In

SFOAuthCoordinator.h

– revokeAuthentication

Revokes the authentication credentials.

- (void)revokeAuthentication

Declared In

SFOAuthCoordinator.h

– handleAdvancedAuthenticationResponse:

Handle an advanced authentication response from the external browser, continuing any in-progress adavanced authentication flow.

- (BOOL)handleAdvancedAuthenticationResponse:(NSURL *)appUrlResponse

Parameters

appUrlResponse

The URL response returned to the app from the external browser.

Return Value

YES if this is a valid URL response from advanced authentication that the coordinator should handle, NO otherwise.

Declared In

SFOAuthCoordinator.h

– handleIDPAuthenticationResponse:

- (BOOL)handleIDPAuthenticationResponse:(NSURL *)appUrlResponse

– beginIDPFlow

- (void)beginIDPFlow

Extension Methods

  authenticating

@property (assign) BOOL authenticating

  session

@property (nonatomic, strong, readonly, nullable) NSURLSession *session

  responseData

@property (nonatomic, strong, nullable) NSMutableData *responseData

  initialRequestLoaded

@property (nonatomic, assign) BOOL initialRequestLoaded

  domainUpdated

@property (nonatomic, assign) BOOL domainUpdated

  approvalCode

@property (nonatomic, copy) NSString *approvalCode

  codeVerifier

@property (nonatomic, strong, nullable) NSString *codeVerifier

  authInfo

@property (nonatomic, strong, nullable) SFOAuthInfo *authInfo

  origWebUserAgent

@property (nonatomic, copy) NSString *origWebUserAgent

  spAppCredentials

@property (nonatomic, strong, nullable) SFOAuthCredentials *spAppCredentials

  authSession

@property (nonatomic, weak, nullable) SFSDKAuthSession *authSession

– initWithAuthSession:

- (instancetype)initWithAuthSession:(SFSDKAuthSession *)authSession

– updateCredentials:

UpdateCredentials and record changes to instanceUrl,accessToken,communityId

- (void)updateCredentials:(NSDictionary *)params

Parameters

params

NV pairs received from token endpoint.

Declared In

SFOAuthCoordinator+Internal.h

– handleUserAgentResponse:

- (void)handleUserAgentResponse:(NSURL *)requestUrl

– notifyDelegateOfFailure:authInfo:

Notify our delegate that we could not log in, and clear authenticating flag

- (void)notifyDelegateOfFailure:(NSError *)error authInfo:(SFOAuthInfo *)info

Declared In

SFOAuthCoordinator+Internal.h

– notifyDelegateOfSuccess:

Notify our delegate that login succeeded, and clear authenticating flag

- (void)notifyDelegateOfSuccess:(SFOAuthInfo *)authInfo

Declared In

SFOAuthCoordinator+Internal.h

– generateApprovalUrlString

Used for testing only.

- (NSString *)generateApprovalUrlString

Return Value

A String representing the prepared authorize url

Declared In

SFOAuthCoordinator+Internal.h

– beginWebViewFlow

- (void)beginWebViewFlow