Created
August 20, 2018 18:57
-
-
Save jalopezsuarez/5ce2c76a9ca170cd0ab53375706e62c8 to your computer and use it in GitHub Desktop.
AuthenticationViewController extension for AuthenticationViewController Swift Library for OAuth2 Authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// OAuthGoogle.swift | |
// AuthenticationViewController | |
// | |
// Created by Jose Antonio Lopez ([email protected]) 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