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)
}
-
The subject’s unique Google id.
Declaration
Swift
var id: String { get } -
The subject’s display name.
Declaration
Swift
var name: String { get }
-
cacheSizeDefault implementationThe 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 } -
tokenTimeToLiveDefault implementationThe 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(request:Extension methodresponse: onSuccess: onFailure: onSkip: ) 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
requestThe
RouterRequestobject used to get information about the request.responseThe
RouterResponseobject used to respond to the request.onSuccessThe closure to invoke in the case of successful authentication.
onFailureThe closure to invoke in the case of an authentication failure.
onSkipThe closure to invoke when the plugin doesn’t recognize the authentication token in the request.
View on GitHub
TypeSafeGoogleToken Protocol Reference