FWOAuth2Manager


@interface FWOAuth2Manager : FWHTTPSessionManager

FWOAuth2Manager

Accessing OAuth 2 Client Properties

  • The service provider identifier used to store and retrieve OAuth credentials by FWOAuthCredential. Equivalent to the hostname of the client baseURL.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSString *_Nonnull serviceProviderIdentifier;
  • The client identifier issued by the authorization server, uniquely representing the registration information provided by the client.

    Declaration

    Objective-C

    @property (nonatomic, copy, readonly) NSString *_Nonnull clientID;
  • Whether to encode client credentials in a Base64-encoded HTTP Authorization header, as opposed to the request body. Defaults to YES.

    Declaration

    Objective-C

    @property (nonatomic) BOOL useHTTPBasicAuthentication;

Creating and Initializing OAuth 2 Managers

  • Creates and initializes an FWOAuth2Manager object with the specified base URL, client identifier, and secret.

    Declaration

    Objective-C

    + (nonnull instancetype)managerWithBaseURL:(nonnull NSURL *)url
                                      clientID:(nonnull NSString *)clientID
                                        secret:(nonnull NSString *)secret;

    Parameters

    url

    The base URL for the HTTP client. This argument must not be nil.

    clientID

    The client identifier issued by the authorization server, uniquely representing the registration information provided by the client. This argument must not be nil.

    secret

    The client secret.

    Return Value

    The newly-initialized OAuth 2 manager

  • Undocumented

    Declaration

    Objective-C

    + (instancetype)managerWithBaseURL:(NSURL *)url
                  sessionConfiguration:(nullable NSURLSessionConfiguration *)configuration
                              clientID:(NSString *)clientID
                                secret:(NSString *)secret;
  • Initializes an FWOAuth2Manager object with the specified base URL, client identifier, and secret. The communication to to the server will use HTTP basic auth by default (use -(id)initWithBaseURL:clientID:secret:withBasicAuth: to change this).

    Declaration

    Objective-C

    - (nonnull id)initWithBaseURL:(nonnull NSURL *)url
                         clientID:(nonnull NSString *)clientID
                           secret:(nonnull NSString *)secret;

    Parameters

    url

    The base URL for the HTTP manager. This argument must not be nil.

    clientID

    The client identifier issued by the authorization server, uniquely representing the registration information provided by the client. This argument must not be nil.

    secret

    The client secret.

    Return Value

    The newly-initialized OAuth 2 client

  • Undocumented

    Declaration

    Objective-C

    - (id)initWithBaseURL:(NSURL *)url
     sessionConfiguration:(nullable NSURLSessionConfiguration *)configuration
                 clientID:(NSString *)clientID
                   secret:(NSString *)secret;

Authenticating

  • Creates and enqueues an NSURLSessionTask to authenticate against the server using a specified username and password, with a designated scope.

    Declaration

    Objective-C

    - (nonnull NSURLSessionTask *)
        authenticateUsingOAuthWithURLString:(nonnull NSString *)URLString
                                   username:(nonnull NSString *)username
                                   password:(nonnull NSString *)password
                                      scope:(nullable NSString *)scope
                                    success:
                                        (nonnull void (^)(
                                            FWOAuthCredential *_Nonnull __strong))
                                            success
                                    failure:(nonnull void (^)(
                                                NSError *_Nonnull __strong))failure;

    Parameters

    URLString

    The URL string used to create the request URL.

    username

    The username used for authentication

    password

    The password used for authentication

    scope

    The authorization scope

    success

    A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server.

    failure

    A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server.

  • Creates and enqueues an NSURLSessionTask to authenticate against the server with a designated scope.

    Declaration

    Objective-C

    - (nonnull NSURLSessionTask *)
        authenticateUsingOAuthWithURLString:(nonnull NSString *)URLString
                                      scope:(nullable NSString *)scope
                                    success:
                                        (nonnull void (^)(
                                            FWOAuthCredential *_Nonnull __strong))
                                            success
                                    failure:(nonnull void (^)(
                                                NSError *_Nonnull __strong))failure;

    Parameters

    URLString

    The URL string used to create the request URL.

    scope

    The authorization scope

    success

    A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server.

    failure

    A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server.

  • Creates and enqueues an NSURLSessionTask to authenticate against the server using the specified refresh token.

    Declaration

    Objective-C

    - (nonnull NSURLSessionTask *)
        authenticateUsingOAuthWithURLString:(nonnull NSString *)URLString
                               refreshToken:(nonnull NSString *)refreshToken
                                    success:
                                        (nonnull void (^)(
                                            FWOAuthCredential *_Nonnull __strong))
                                            success
                                    failure:(nonnull void (^)(
                                                NSError *_Nonnull __strong))failure;

    Parameters

    URLString

    The URL string used to create the request URL.

    refreshToken

    The OAuth refresh token

    success

    A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server.

    failure

    A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server.

  • Creates and enqueues an NSURLSessionTask to authenticate against the server with an authorization code, redirecting to a specified URI upon successful authentication.

    Declaration

    Objective-C

    - (nonnull NSURLSessionTask *)
        authenticateUsingOAuthWithURLString:(nonnull NSString *)URLString
                                       code:(nonnull NSString *)code
                                redirectURI:(nonnull NSString *)uri
                                    success:
                                        (nonnull void (^)(
                                            FWOAuthCredential *_Nonnull __strong))
                                            success
                                    failure:(nonnull void (^)(
                                                NSError *_Nonnull __strong))failure;

    Parameters

    URLString

    The URL string used to create the request URL.

    code

    The authorization code

    uri

    The URI to redirect to after successful authentication

    success

    A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server.

    failure

    A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server.

  • Creates and enqueues an NSURLSessionTask to authenticate against the server with the specified parameters.

    Declaration

    Objective-C

    - (nonnull NSURLSessionTask *)
        authenticateUsingOAuthWithURLString:(nonnull NSString *)URLString
                                 parameters:(nonnull NSDictionary *)parameters
                                    headers:
                                        (nullable NSDictionary<NSString *,
                                                               NSString *> *)headers
                                    success:
                                        (nonnull void (^)(
                                            FWOAuthCredential *_Nonnull __strong))
                                            success
                                    failure:(nonnull void (^)(
                                                NSError *_Nonnull __strong))failure;

    Parameters

    URLString

    The URL string used to create the request URL.

    parameters

    The parameters to be encoded and set in the request HTTP body.

    headers

    The headers appended to the default headers for this request.

    success

    A block object to be executed when the request operation finishes successfully. This block has no return value and takes a single argument: the OAuth credential returned by the server.

    failure

    A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a single argument: the error returned from the server.