Skip to content

Instantly share code, notes, and snippets.

@jalopezsuarez
Created August 20, 2018 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalopezsuarez/5ce2c76a9ca170cd0ab53375706e62c8 to your computer and use it in GitHub Desktop.
Save jalopezsuarez/5ce2c76a9ca170cd0ab53375706e62c8 to your computer and use it in GitHub Desktop.
AuthenticationViewController extension for AuthenticationViewController Swift Library for OAuth2 Authentication
//
// OAuthGoogle.swift
// AuthenticationViewController
//
// Created by Jose Antonio Lopez (jalopezsuarez@gmail.com) on 01/01/2018.
// Copyright © 2018 Jose Antonio Lopez. All rights reserved.
//
import Foundation
import AuthenticationViewController
struct OAuthGoogle: AuthenticationProvider {
let title: String?
let clientId: String
let clientSecret: String
let scopes: [String]
let redirectURI = "com.googleusercontent.apps.188766122934-0t21j64fd4qmcomewpho6jeqwxe6kpwq:/oauth2redirect"
var authorizationURL: URL {
var request = ""
request = request + "https://accounts.google.com/o/oauth2/auth"
request = request + "?" + "client_id=\(clientId)"
request = request + "&" + "scope=\(scopes.joined(separator: "+"))"
request = request + "&" + "redirect_uri=\(redirectURI)"
request = request + "&" + "response_type=code"
return URL(string: request)!
}
var accessTokenURL: URL {
return URL(string: "https://accounts.google.com/o/oauth2/token")!
}
var parameters: [String: String] {
return ["grant_type": "authorization_code", "redirect_uri": redirectURI]
}
// MARK: Initialisers
init(clientId: String, clientSecret: String, scopes: [String]) {
self.clientId = clientId
self.clientSecret = clientSecret
self.scopes = scopes
self.title = "Google"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment