Authentication

public class Authentication

Wraper around OAuthSwift and KeychainAccess to authenticate to Google APIs while automatically saving the tokens into the keychain

  • Creates an Authentication instance with the configuration from an OAuth App

    Declaration

    Swift

    public init(
        appID: String,
        consumerSecret: String,
        scope: String,
        keychainService: String
    )

    Parameters

    appID

    The app ID from Google (Part of the consumer key in front of .apps.googleusercontent.com or part of the redirect URI after com.googleusercontent.apps.

    consumerSecret

    OAuth consumer secret

    scope

    scope of the authorization

    keychainService

    string used for the keychain identification, usually your Bundle ID

  • Authenticates the user

    If the keychain has a token saved it retreives this and returns without calling Google. After successful authentication the tokens are saved in the keychain

    Declaration

    Swift

    public func authenticate(
        authenticationPresentationContextProvider: ASWebAuthenticationPresentationContextProviding,
        completion: @escaping OAuthSwift.TokenCompletionHandler
    )
  • Sends a GET request with the neccessary authnetication headers

    Handels token renewals automatically, including saving the updated token to the keychain

    Declaration

    Swift

    @discardableResult
    public func startAuthorizedGETRequest(_ url: URLConvertible, completionHandler completion: @escaping OAuthSwiftHTTPRequest.CompletionHandler) -> OAuthSwiftRequestHandle?

    Parameters

    url

    URL to call

    completion

    OAuthSwiftHTTPRequest.CompletionHandler

    Return Value

    OAuthSwiftRequestHandle?