FRUser

@objc
public class FRUser : NSObject, NSSecureCoding

FRUser represents authenticated user session as FRUser object

Properties

  • Singleton instance represents currently authenticated user.

    Note

    If SDK has not been started using FRAuth.start(), FRUser.currentUser returns nil even if user session has previously authenticated, and valid. FRUser.currentUser would only returns an object when there is either or both of following:

    • Session Token authenticated by AM’s Authentication Tree
    • OAuth2 token set issued by previously authenticated Session Token

    Declaration

    Swift

    @objc
    public static var currentUser: FRUser? { get }
  • AccessToken object associated with FRUser object

    Declaration

    Swift

    @objc
    public var token: AccessToken? { get set }

Login

  • Logs-in user based on configuration value initialized through FRAuth.start()

    Note:

    • When there is already authenticated user’s session (either with Session Token and/or OAuth2 token set), login method returns an error. If Session Token exists, but not OAuth2 token set, use FRUser.currentUser.getAccessToken() to obtain OAuth2 token set using Session Token.
    • FRAuth.start() must be called prior to call login

    Declaration

    Swift

    @objc
    public static func login(completion: @escaping NodeCompletion<FRUser>)

    Parameters

    completion

    Completion callback which returns FRUser instance (also accessible through FRUser.currentUser), and/or any error encountered during authentication

Register

  • Registers a user based on configuration value initialized through FRAuth.start()

    Note:

    • When there is already authenticated user’s session (either with Session Token and/or OAuth2 token set), register method returns an error. If Session Token exists, but not OAuth2 token set, use FRUser.currentUser.getAccessToken() to obtain OAuth2 token set using Session Token.
    • FRAuth.start() must be called prior to call register

    Declaration

    Swift

    @objc
    public static func register(completion: @escaping NodeCompletion<FRUser>)

    Parameters

    completion

    Completion callback which returns FRUser instance (also accessible through FRUser.currentUser), and/or any error encountered during registration

Logout

  • Logs-out currently authenticated user session

    Note

    logout method invokes 2 APIs to invalidate user’s session: 1) invokes /sessions/?_action=logout to invalidate Session Token, 2) /token/revoke to invalidate access_token and/or refresh_token (if refresh_token was granted), and 3) if id_token exists, it invokes /connect/endSession to invalidate OIDC session

    Declaration

    Swift

    @objc
    public func logout()
  • Logs-out currently authenticated user session. If oauth2Clint.signoutRedirectUri is not nil, will logout the user in the browser as well

    Declaration

    Swift

    public func logout(presentingViewController: UIViewController, browserType: BrowserType = .authSession)

    Parameters

    presentingViewController

    ViewController to present the logout broser view from

    browserType

    An external user-agent type; default to Authentication Service. This must match the browser type used during login

AccessToken

  • Retrieves access_token from Keychain storage, and if current access_token is expired, then consumes refresh_token to refresh access_token, and returns FRUser with newly granted access_token

    Declaration

    Swift

    @objc
    public func getAccessToken(completion: @escaping UserCallback)

    Parameters

    completion

    Completion block which returns newly refreshed FRUser object

  • Retrieves AccessToken from Keychain storage, and if current AccessToken is about to expire, then consumes refresh_token to refresh AccessToken, and returns FRUser with newly granted AccessToken

    Note

    This method performs sync network requests; be careful on calling this method in UI Thread

    Throws

    ConfigError / TokenError / AuthError

    Declaration

    Swift

    @objc
    public func getAccessToken() throws -> FRUser

    Return Value

    Updated FRUser object instance with newly granted Accesstoken

  • Revokes current OAuth2 token using access_token, or refresh_token.

    Declaration

    Swift

    @objc
    public func revokeAccessToken(completion: @escaping UserCallback)

    Parameters

    completion

    Completion callback that notifies the result of operation

  • Refreshes user’s session with refresh_token regardless of validity of current access_token

    Declaration

    Swift

    @objc
    public func refresh(completion: @escaping UserCallback)

    Parameters

    completion

    Completion callback that notifies the result of operation

  • Refreshes user’s session with refresh_token synchronously regardless of validity of current access_token

    Throws

    TokenError

    Declaration

    Swift

    @objc
    public func refreshSync() throws -> FRUser

    Return Value

    FRUser object with newly renewed OAuth2 token

UserInfo

  • Retrieves currently authenticated user’s UserInfo from /userinfo endpoint

    Declaration

    Swift

    @objc
    public func getUserInfo(completion: @escaping UserInfoCallback)

    Parameters

    completion

    Callback block which returns UserInfo object; UserInfo result is also updated to calling FRUser object instance

Authorization Header

  • Builds Authorization header value with currently given access_token

    Declaration

    Swift

    @objc
    public func buildAuthHeader() -> String

    Return Value

    String value for Authorization header in “TOKEN_TYPE ACCESS_TOKEN” format

Centralized Login (External User Agent)

  • Creates Browser object to perform Centralized Login (an external user-agent /authorize flow)

    Declaration

    Swift

    @objc
    public static func browser() -> BrowserBuilder?

    Return Value

    BrowserBuilder object that can progressively construct Browser object with configuration; BrowserBuilder may return nil if there is another Builder instance running in the application.

Debug

  • Debug description of FRUser and associated properties

    Declaration

    Swift

    override public var debugDescription: String { get }

NSSecureCoding

  • Boolean value of whether SecureCoding is supported or not

    Declaration

    Swift

    public class var supportsSecureCoding: Bool { get }
  • Initializes FRUser object with NSCoder

    Declaration

    Swift

    convenience required public init?(coder aDecoder: NSCoder)

    Parameters

    aDecoder

    NSCoder

  • Encodes FRUser object with NSCoder

    Declaration

    Swift

    public func encode(with aCoder: NSCoder)

    Parameters

    aCoder

    NSCoder