TokenManagementPolicy

@objc(FRTokenManagementPolicy)
public class TokenManagementPolicy : NSObject
TokenManagementPolicy is mainly responsible to determine to inject OAuth2 authorization header in the request, and whether or not response of the request is OAuth2 token validation failure, so that SDK should renew OAuth2 token, and retry request with updated OAuth2 token

TokenManagementPolicy performs two major responsibilities:

    1. Automatically injects `Authorization` header in the request with currently authenticated `FRUser.currentUser.token` value; if no currently authenticated user session is found, then it continues with the original request
    2. Upon receiving request response, it invokes `TokenManagementPolicyDelegate.evaluateTokenRefresh` to evaluate whether or not the response is due to OAuth2 token validation failure (i.e. token expired). The application layer can determine if the response is required to renew OAuth2 token set, and return `true` in the delegation method which then enforce SDK to renew OAuth2 token set with `refresh_token`, and/or `SSOToken`, and retry the original request with updated OAuth2 token set. If OAuth2 token renewal fails, or same response is returned after renewing OAuth2 tokens, SDK terminates the request, and returns the failure response.

**Note** TokenManagementPolicy only enforces its policy for given URLs. If given URLRequest does not match any of given URLs, then it proceeds as it is.

Usage

 // Step 1 - Register FRURLProtocol
 URLProtocol.registerClass(FRURLProtocol.self)

 // Step 2 - Initialize TokenManagementPolicy object
 let tokenManagementPolicy = TokenManagementPolicy(validatingURL: [URL, URL,...], delegate: self)

 // Step 3 - Implement delegate method if needed

 // Step 4 - Assign TokenManagementPolicy in FRURLProtocol
 FRURLProtocol.tokenManagementPolicy = tokenManagementPolicy

 // Step 5 - Configure URLProtocol in the application's URLSessionConfiguration
 let config = URLSessionConfiguration.default
 config.protocolClasses = [FRURLProtocol.self]
 let urlSession = URLSession(configuration: config)

Property

Init

  • Initializes TokenManagementPolicy with delegation

    Declaration

    Swift

    @objc
    public init(validatingURL: [URL], delegate: TokenManagementPolicyDelegate? = nil)

    Parameters

    validatingURL

    URLs to be validated for TokenManagementPolicy

    delegate

    delegation to enforce token policy evaluation