TypeSafeFacebookToken

public protocol TypeSafeFacebookToken: TypeSafeFacebook

A protocol that a user’s type can conform to representing a user authenticated using a Facebook OAuth token.

Usage Example:

public struct ExampleProfile: TypeSafeFacebookToken {
   static var appID: String? = "yourAppID"     // The id of your Facebook App
   let id: String                              // Protocol requirement
   let name: String                            // Protocol requirement: subject's display name
   let email: String?                          // Optional Facebook field: may not be granted
}
router.get("/facebookProfile") { (user: ExampleProfile, respondWith: (ExampleProfile?, RequestError?) -> Void) in
   respondWith(user, nil)
}

A pre-defined FacebookTokenProfile type has been provided for use if you do not wish to define your own type, and provides an example of how to access the various structured data types (such as profile picture information) provided by the Facebook API.

  • id

    The application-scoped ID field. Note that this field uniquely identifies a user wihin the context of the application represented by the token.

    Declaration

    Swift

    var id: String
  • The subject’s display name.

    Declaration

    Swift

    var name: String
  • cacheSize Default implementation

    The maximum size of the in-memory token cache for this type. If not specified, then the cache has an unlimited size.

    Default Implementation

    A default value for the cache size of 0, which means that there is no limit on how many profiles the token cache can store.

    Declaration

    Swift

    static var cacheSize: Int
  • tokenTimeToLive Default implementation

    The time in seconds since the user profile was generated that the access token will be considered valid.

    Default Implementation

    Default for tokenTimeToLive is nil meaning the token will be considered valid as long as it is in the cache.

    Declaration

    Swift

    static var tokenTimeToLive: TimeInterval?
  • Authenticate an incoming request using a Facebook OAuth token. This type of authentication handles requests with a header of ‘X-token-type: FacebookToken’ and an appropriate OAuth token supplied via the ‘access_token’ header.

    Note: this function has been implemented for you.

    Declaration

    Swift

    public static func authenticate(request: RouterRequest, response: RouterResponse,
                                    onSuccess: @escaping (Self) -> Void,
                                    onFailure: @escaping (HTTPStatusCode?, [String : String]?) -> Void,
                                    onSkip: @escaping (HTTPStatusCode?, [String : String]?) -> Void)

    Parameters

    request

    The RouterRequest object used to get information about the request.

    response

    The RouterResponse object used to respond to the request.

    onSuccess

    The closure to invoke in the case of successful authentication.

    onFailure

    The closure to invoke in the case of an authentication failure.

    onSkip

    The closure to invoke when the plugin doesn’t recognize the authentication token in the request.