TypeSafeGoogleToken

public protocol TypeSafeGoogleToken : TypeSafeGoogle

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

Usage Example:

public struct ExampleProfile: TypeSafeGoogleToken {
    let id: String                              // Protocol requirement: subject's unique id
    let name: String                            // Protocol requirement: subject's display name
    let email: String?                          // Optional field: may not be granted
}

router.get("/googleProfile") { (user: ExampleProfile, respondWith: (ExampleProfile?, RequestError?) -> Void) in
    respondWith(user, nil)
}

Instance fields

  • id

    The subject’s unique Google id.

    Declaration

    Swift

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

    Declaration

    Swift

    var name: String { get }

Static fields

  • 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 { get }
  • 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? { get }
  • Authenticate an incoming request using a Google OAuth token. This type of authentication handles requests with a header of ‘X-token-type: GoogleToken’ 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.