From 6cee0840eeb98f7f1036aa2337e9cbac8b56dc3d Mon Sep 17 00:00:00 2001 From: wibe Date: Tue, 12 Mar 2024 09:07:29 +0100 Subject: [PATCH] first draft rename Signed-off-by: wibe --- .../Services/DeviantArt/DeviantArtRouter.swift | 10 +++++----- Sources/Imperial/Services/Imgur/ImgurRouter.swift | 6 +++--- .../Services/Microsoft/MicrosoftRouter.swift | 10 +++++----- .../Imperial/Services/Mixcloud/MixcloudRouter.swift | 10 +++++----- Sources/ImperialAuth0/Auth0.swift | 4 ++-- Sources/ImperialAuth0/Auth0Router.swift | 10 +++++----- .../Routing/FederatedServiceRouter.swift | 8 ++++---- Sources/ImperialCore/ServiceRegister.swift | 12 ++++++------ Sources/ImperialCore/Services/FederatedService.swift | 2 +- Sources/ImperialDiscord/Discord.swift | 4 ++-- Sources/ImperialDiscord/DiscordRouter.swift | 6 +++--- Sources/ImperialDropbox/Dropbox.swift | 4 ++-- Sources/ImperialDropbox/DropboxRouter.swift | 9 ++++----- Sources/ImperialFacebook/Facebook.swift | 4 ++-- Sources/ImperialFacebook/FacebookRouter.swift | 8 ++++---- Sources/ImperialGitHub/GitHub.swift | 4 ++-- Sources/ImperialGitHub/GitHubRouter.swift | 6 +++--- Sources/ImperialGitlab/Gitlab.swift | 4 ++-- Sources/ImperialGitlab/GitlabRouter.swift | 6 +++--- Sources/ImperialGoogle/JWT/GoogleJWT.swift | 4 ++-- Sources/ImperialGoogle/JWT/GoogleJWTRouter.swift | 10 +++++----- Sources/ImperialGoogle/Standard/Google.swift | 4 ++-- Sources/ImperialGoogle/Standard/GoogleRouter.swift | 8 ++++---- Sources/ImperialKeycloak/Keycloak.swift | 4 ++-- Sources/ImperialKeycloak/KeycloakRouter.swift | 10 +++++----- Sources/ImperialMicrosoft/Microsoft.swift | 4 ++-- Sources/ImperialMicrosoft/MicrosoftRouter.swift | 8 ++++---- Sources/ImperialShopify/Shopify.swift | 4 ++-- Sources/ImperialShopify/ShopifyRouter.swift | 9 +++++---- 29 files changed, 96 insertions(+), 96 deletions(-) diff --git a/Sources/Imperial/Services/DeviantArt/DeviantArtRouter.swift b/Sources/Imperial/Services/DeviantArt/DeviantArtRouter.swift index 66e8dd9..1227a8f 100644 --- a/Sources/Imperial/Services/DeviantArt/DeviantArtRouter.swift +++ b/Sources/Imperial/Services/DeviantArt/DeviantArtRouter.swift @@ -5,12 +5,12 @@ public class DeviantArtRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String)throws -> (Future) public var scope: [String] = [] - public var callbackURL: String + public var redirectURL: String public let accessTokenURL: String = "https://www.deviantart.com/oauth2/token" - public required init(callback: String, completion: @escaping (Request, String)throws -> (Future)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String)throws -> (Future)) throws { self.tokens = try DeviantArtAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } @@ -23,7 +23,7 @@ public class DeviantArtRouter: FederatedServiceRouter { } return "https://www.deviantart.com/oauth2/authorize?" + "client_id=\(self.tokens.clientID)&" + - "redirect_uri=\(self.callbackURL)&\(scope)" + + "redirect_uri=\(self.redirectURL)&\(scope)" + "response_type=code" } @@ -37,7 +37,7 @@ public class DeviantArtRouter: FederatedServiceRouter { throw Abort(.badRequest, reason: "Missing 'code' key in URL query") } - let body = DeviantArtCallbackBody(code: code, clientId: self.tokens.clientID, clientSecret: self.tokens.clientSecret, redirectURI: self.callbackURL) + let body = DeviantArtCallbackBody(code: code, clientId: self.tokens.clientID, clientSecret: self.tokens.clientSecret, redirectURI: self.redirectURL) return try body.encode(using: request).flatMap(to: Response.self) { request in guard let url = URL(string: self.accessTokenURL) else { throw Abort(.internalServerError, reason: "Unable to convert String '\(self.accessTokenURL)' to URL") diff --git a/Sources/Imperial/Services/Imgur/ImgurRouter.swift b/Sources/Imperial/Services/Imgur/ImgurRouter.swift index 52e3756..d2a22b1 100644 --- a/Sources/Imperial/Services/Imgur/ImgurRouter.swift +++ b/Sources/Imperial/Services/Imgur/ImgurRouter.swift @@ -5,12 +5,12 @@ public class ImgurRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String)throws -> (Future) public var scope: [String] = [] - public var callbackURL: String + public var redirectURL: String public let accessTokenURL: String = "https://api.imgur.com/oauth2/token" - public required init(callback: String, completion: @escaping (Request, String)throws -> (Future)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String)throws -> (Future)) throws { self.tokens = try ImgurAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } diff --git a/Sources/Imperial/Services/Microsoft/MicrosoftRouter.swift b/Sources/Imperial/Services/Microsoft/MicrosoftRouter.swift index 2e6ec45..da81dd7 100644 --- a/Sources/Imperial/Services/Microsoft/MicrosoftRouter.swift +++ b/Sources/Imperial/Services/Microsoft/MicrosoftRouter.swift @@ -7,16 +7,16 @@ public class MicrosoftRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String)throws -> (Future) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public var tenantID: String { Environment.get(MicrosoftRouter.tenantIDEnvKey) ?? "common" } public var accessTokenURL: String { "https://login.microsoftonline.com/\(self.tenantID)/oauth2/v2.0/token" } public required init( - callback: String, + redirectURL: String, completion: @escaping (Request, String) throws -> (Future) ) throws { self.tokens = try MicrosoftAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } @@ -24,7 +24,7 @@ public class MicrosoftRouter: FederatedServiceRouter { return "https://login.microsoftonline.com/\(self.tenantID)/oauth2/v2.0/authorize?" + "client_id=\(self.tokens.clientID)&" + "response_type=code&" - + "redirect_uri=\(self.callbackURL)&" + + "redirect_uri=\(self.redirectURL)&" + "response_mode=query&" + "scope=\(scope.joined(separator: "%20"))&" + "prompt=consent" @@ -45,7 +45,7 @@ public class MicrosoftRouter: FederatedServiceRouter { code: code, clientId: self.tokens.clientID, clientSecret: self.tokens.clientSecret, - redirectURI: self.callbackURL, + redirectURI: self.redirectURL, scope: scope.joined(separator: "%20") ) diff --git a/Sources/Imperial/Services/Mixcloud/MixcloudRouter.swift b/Sources/Imperial/Services/Mixcloud/MixcloudRouter.swift index 5f832a7..9ca3c1c 100644 --- a/Sources/Imperial/Services/Mixcloud/MixcloudRouter.swift +++ b/Sources/Imperial/Services/Mixcloud/MixcloudRouter.swift @@ -5,19 +5,19 @@ public class MixcloudRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String)throws -> (Future) public var scope: [String] = [] - public var callbackURL: String + public var redirectURL: String public let accessTokenURL: String = "https://www.mixcloud.com/oauth/access_token" - public required init(callback: String, completion: @escaping (Request, String)throws -> (Future)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String)throws -> (Future)) throws { self.tokens = try MixcloudAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } public func authURL(_ request: Request) throws -> String { return "https://www.mixcloud.com/oauth/authorize?" + "client_id=\(self.tokens.clientID)&" + - "redirect_uri=\(self.callbackURL)" + "redirect_uri=\(self.redirectURL)" } public func fetchToken(from request: Request)throws -> Future { @@ -30,7 +30,7 @@ public class MixcloudRouter: FederatedServiceRouter { throw Abort(.badRequest, reason: "Missing 'code' key in URL query") } - let body = MixcloudCallbackBody(code: code, clientId: self.tokens.clientID, clientSecret: self.tokens.clientSecret, redirectURI: self.callbackURL) + let body = MixcloudCallbackBody(code: code, clientId: self.tokens.clientID, clientSecret: self.tokens.clientSecret, redirectURI: self.redirectURL) return try request .client() .get(self.accessTokenURL) { request in diff --git a/Sources/ImperialAuth0/Auth0.swift b/Sources/ImperialAuth0/Auth0.swift index b9c0794..645e993 100644 --- a/Sources/ImperialAuth0/Auth0.swift +++ b/Sources/ImperialAuth0/Auth0.swift @@ -10,11 +10,11 @@ public class Auth0: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try Auth0Router(callback: callback, completion: completion) + self.router = try Auth0Router(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialAuth0/Auth0Router.swift b/Sources/ImperialAuth0/Auth0Router.swift index d806408..9781d45 100644 --- a/Sources/ImperialAuth0/Auth0Router.swift +++ b/Sources/ImperialAuth0/Auth0Router.swift @@ -8,7 +8,7 @@ public class Auth0Router: FederatedServiceRouter { public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [ ] public var requiredScopes = [ "openid" ] - public let callbackURL: String + public let redirectURL: String public let accessTokenURL: String public var service: OAuthService = .auth0 public let callbackHeaders = HTTPHeaders([("Content-Type", "application/x-www-form-urlencoded")]) @@ -17,12 +17,12 @@ public class Auth0Router: FederatedServiceRouter { return self.baseURL.finished(with: "/") + path } - public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { let auth = try Auth0Auth() self.tokens = auth self.baseURL = "https://\(auth.domain)" self.accessTokenURL = baseURL.finished(with: "/") + "oauth/token" - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } @@ -32,7 +32,7 @@ public class Auth0Router: FederatedServiceRouter { var params=[ "response_type=code", "client_id=\(self.tokens.clientID)", - "redirect_uri=\(self.callbackURL)", + "redirect_uri=\(self.redirectURL)", ] let allScopes = self.scope + self.requiredScopes @@ -49,6 +49,6 @@ public class Auth0Router: FederatedServiceRouter { Auth0CallbackBody(clientId: self.tokens.clientID, clientSecret: self.tokens.clientSecret, code: code, - redirectURI: self.callbackURL) + redirectURI: self.redirectURL) } } diff --git a/Sources/ImperialCore/Routing/FederatedServiceRouter.swift b/Sources/ImperialCore/Routing/FederatedServiceRouter.swift index 623a460..2a71100 100644 --- a/Sources/ImperialCore/Routing/FederatedServiceRouter.swift +++ b/Sources/ImperialCore/Routing/FederatedServiceRouter.swift @@ -26,7 +26,7 @@ public protocol FederatedServiceRouter { var service: OAuthService { get } /// The URL (or URI) for that route that the provider will fire when the user authenticates with the OAuth provider. - var callbackURL: String { get } + var redirectURL: String { get } /// HTTPHeaders for the Callback request var callbackHeaders: HTTPHeaders { get } @@ -43,7 +43,7 @@ public protocol FederatedServiceRouter { /// - callback: The callback URL that the OAuth provider will redirect to after authenticating the user. /// - completion: The completion handler that will be fired at the end of the `callback` route. The access token is passed into it. /// - Throws: Any errors that could occur in the implementation. - init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws + init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws /// Configures the `authenticate` and `callback` routes with the droplet. /// @@ -78,7 +78,7 @@ extension FederatedServiceRouter { public var callbackHeaders: HTTPHeaders { [:] } public func configureRoutes(withAuthURL authURL: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, on router: RoutesBuilder) throws { - router.get(callbackURL.pathComponents, use: callback) + router.get(redirectURL.pathComponents, use: callback) router.get(authURL.pathComponents) { req -> EventLoopFuture in let redirect: Response = req.redirect(to: try self.authURL(req)) guard let authenticateCallback = authenticateCallback else { @@ -135,7 +135,7 @@ extension FederatedServiceRouter { } public var redirectURIItem: URLQueryItem { - .init(name: "redirect_uri", value: callbackURL) + .init(name: "redirect_uri", value: redirectURL) } public var scopeItem: URLQueryItem { diff --git a/Sources/ImperialCore/ServiceRegister.swift b/Sources/ImperialCore/ServiceRegister.swift index 3de41f1..5364cd0 100644 --- a/Sources/ImperialCore/ServiceRegister.swift +++ b/Sources/ImperialCore/ServiceRegister.swift @@ -18,7 +18,7 @@ extension RoutesBuilder { from provider: OAuthProvider.Type, authenticate authUrl: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))? = nil, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> EventLoopFuture ) throws where OAuthProvider: FederatedService { @@ -26,7 +26,7 @@ extension RoutesBuilder { routes: self, authenticate: authUrl, authenticateCallback: authenticateCallback, - callback: callback, + redirectURL: redirectURL, scope: scope, completion: completion ) @@ -47,12 +47,12 @@ extension RoutesBuilder { from provider: OAuthProvider.Type, authenticate authUrl: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))? = nil, - callback: String, + redirectURL: String, scope: [String] = [], - redirect redirectURL: String + redirect: String ) throws where OAuthProvider: FederatedService { - try self.oAuth(from: OAuthProvider.self, authenticate: authUrl, authenticateCallback: authenticateCallback, callback: callback, scope: scope) { (request, _) in - let redirect: Response = request.redirect(to: redirectURL) + try self.oAuth(from: OAuthProvider.self, authenticate: authUrl, authenticateCallback: authenticateCallback, redirectURL: redirectURL, scope: scope) { (request, _) in + let redirect: Response = request.redirect(to: redirect) return request.eventLoop.makeSucceededFuture(redirect) } } diff --git a/Sources/ImperialCore/Services/FederatedService.swift b/Sources/ImperialCore/Services/FederatedService.swift index 12e4d7e..086719a 100644 --- a/Sources/ImperialCore/Services/FederatedService.swift +++ b/Sources/ImperialCore/Services/FederatedService.swift @@ -42,5 +42,5 @@ public protocol FederatedService { /// - scope: The scopes to send to the provider to request access to. /// - completion: The completion handler that will fire at the end of the callback route. The access token is passed into the callback and the response that is returned will be returned from the callback route. This will usually be a redirect back to the app. /// - Throws: Any errors that occur in the implementation. - init(routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, callback: String, scope: [String], completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws + init(routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, redirectURL: String, scope: [String], completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws } diff --git a/Sources/ImperialDiscord/Discord.swift b/Sources/ImperialDiscord/Discord.swift index fa2db84..cbc45e1 100644 --- a/Sources/ImperialDiscord/Discord.swift +++ b/Sources/ImperialDiscord/Discord.swift @@ -10,11 +10,11 @@ public class Discord: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try DiscordRouter(callback: callback, completion: completion) + self.router = try DiscordRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialDiscord/DiscordRouter.swift b/Sources/ImperialDiscord/DiscordRouter.swift index 6932a86..1afeefc 100644 --- a/Sources/ImperialDiscord/DiscordRouter.swift +++ b/Sources/ImperialDiscord/DiscordRouter.swift @@ -8,14 +8,14 @@ public class DiscordRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public let accessTokenURL: String = "\(DiscordRouter.baseURL.finished(with: "/"))api/oauth2/token" public let service: OAuthService = .discord public let callbackHeaders = HTTPHeaders([("Content-Type", "application/x-www-form-urlencoded")]) - public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try DiscordAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } diff --git a/Sources/ImperialDropbox/Dropbox.swift b/Sources/ImperialDropbox/Dropbox.swift index 667f7d9..c587986 100644 --- a/Sources/ImperialDropbox/Dropbox.swift +++ b/Sources/ImperialDropbox/Dropbox.swift @@ -10,11 +10,11 @@ public class Dropbox: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try DropboxRouter(callback: callback, completion: completion) + self.router = try DropboxRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialDropbox/DropboxRouter.swift b/Sources/ImperialDropbox/DropboxRouter.swift index 78d6ab8..da33074 100644 --- a/Sources/ImperialDropbox/DropboxRouter.swift +++ b/Sources/ImperialDropbox/DropboxRouter.swift @@ -5,7 +5,7 @@ public class DropboxRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public let accessTokenURL: String = "https://api.dropboxapi.com/oauth2/token" public var callbackHeaders: HTTPHeaders { @@ -17,9 +17,9 @@ public class DropboxRouter: FederatedServiceRouter { public let service: OAuthService = .dropbox - public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try DropboxAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } @@ -43,8 +43,7 @@ public class DropboxRouter: FederatedServiceRouter { } public func callbackBody(with code: String) -> ResponseEncodable { - DropboxCallbackBody(code: code, - redirectURI: callbackURL) + DropboxCallbackBody(code: code, redirectURI: redirectURL) } } diff --git a/Sources/ImperialFacebook/Facebook.swift b/Sources/ImperialFacebook/Facebook.swift index 41fdde7..11819f0 100644 --- a/Sources/ImperialFacebook/Facebook.swift +++ b/Sources/ImperialFacebook/Facebook.swift @@ -10,11 +10,11 @@ public class Facebook: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try FacebookRouter(callback: callback, completion: completion) + self.router = try FacebookRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialFacebook/FacebookRouter.swift b/Sources/ImperialFacebook/FacebookRouter.swift index 7f404ab..268b3ff 100644 --- a/Sources/ImperialFacebook/FacebookRouter.swift +++ b/Sources/ImperialFacebook/FacebookRouter.swift @@ -6,7 +6,7 @@ public class FacebookRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public var accessTokenURL: String = "https://graph.facebook.com/v3.2/oauth/access_token" public let service: OAuthService = .facebook @@ -29,9 +29,9 @@ public class FacebookRouter: FederatedServiceRouter { return url.absoluteString } - public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try FacebookAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } @@ -39,7 +39,7 @@ public class FacebookRouter: FederatedServiceRouter { FacebookCallbackBody(code: code, clientId: tokens.clientID, clientSecret: tokens.clientSecret, - redirectURI: callbackURL) + redirectURI: redirectURL) } } diff --git a/Sources/ImperialGitHub/GitHub.swift b/Sources/ImperialGitHub/GitHub.swift index ee511d4..956357f 100644 --- a/Sources/ImperialGitHub/GitHub.swift +++ b/Sources/ImperialGitHub/GitHub.swift @@ -10,11 +10,11 @@ public class GitHub: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try GitHubRouter(callback: callback, completion: completion) + self.router = try GitHubRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialGitHub/GitHubRouter.swift b/Sources/ImperialGitHub/GitHubRouter.swift index a1a53d0..3621320 100644 --- a/Sources/ImperialGitHub/GitHubRouter.swift +++ b/Sources/ImperialGitHub/GitHubRouter.swift @@ -7,7 +7,7 @@ public class GitHubRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public let accessTokenURL: String = "\(GitHubRouter.baseURL.finished(with: "/"))login/oauth/access_token" public let service: OAuthService = .github public let callbackHeaders: HTTPHeaders = { @@ -16,9 +16,9 @@ public class GitHubRouter: FederatedServiceRouter { return headers }() - public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try GitHubAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } diff --git a/Sources/ImperialGitlab/Gitlab.swift b/Sources/ImperialGitlab/Gitlab.swift index 62b88ef..b1fa5f2 100644 --- a/Sources/ImperialGitlab/Gitlab.swift +++ b/Sources/ImperialGitlab/Gitlab.swift @@ -10,11 +10,11 @@ public class Gitlab: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try GitlabRouter(callback: callback, completion: completion) + self.router = try GitlabRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialGitlab/GitlabRouter.swift b/Sources/ImperialGitlab/GitlabRouter.swift index de35b25..4f900c1 100644 --- a/Sources/ImperialGitlab/GitlabRouter.swift +++ b/Sources/ImperialGitlab/GitlabRouter.swift @@ -8,13 +8,13 @@ public class GitlabRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public let accessTokenURL: String = "\(GitlabRouter.baseURL.finished(with: "/"))oauth/token" public let service: OAuthService = .gitlab - public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try GitlabAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } diff --git a/Sources/ImperialGoogle/JWT/GoogleJWT.swift b/Sources/ImperialGoogle/JWT/GoogleJWT.swift index f610d29..9a1d87c 100644 --- a/Sources/ImperialGoogle/JWT/GoogleJWT.swift +++ b/Sources/ImperialGoogle/JWT/GoogleJWT.swift @@ -9,11 +9,11 @@ public class GoogleJWT: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try GoogleJWTRouter(callback: callback, completion: completion) + self.router = try GoogleJWTRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialGoogle/JWT/GoogleJWTRouter.swift b/Sources/ImperialGoogle/JWT/GoogleJWTRouter.swift index 3664067..87a6342 100644 --- a/Sources/ImperialGoogle/JWT/GoogleJWTRouter.swift +++ b/Sources/ImperialGoogle/JWT/GoogleJWTRouter.swift @@ -8,7 +8,7 @@ public final class GoogleJWTRouter: FederatedServiceRouter { public var tokens: FederatedServiceTokens public var callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public var callbackURL: String + public var redirectURL: String public var accessTokenURL: String = "https://www.googleapis.com/oauth2/v4/token" public var authURL: String public let service: OAuthService = .googleJWT @@ -18,10 +18,10 @@ public final class GoogleJWTRouter: FederatedServiceRouter { return headers }() - public init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try GoogleJWTAuth() - self.callbackURL = callback - self.authURL = callback + self.redirectURL = redirectURL + self.authURL = redirectURL self.callbackCompletion = completion } @@ -48,7 +48,7 @@ public final class GoogleJWTRouter: FederatedServiceRouter { } public func authenticate(_ request: Request) throws -> EventLoopFuture { - let redirect: Response = request.redirect(to: self.callbackURL) + let redirect: Response = request.redirect(to: self.redirectURL) return request.eventLoop.makeSucceededFuture(redirect) } diff --git a/Sources/ImperialGoogle/Standard/Google.swift b/Sources/ImperialGoogle/Standard/Google.swift index 1589f3a..aaf3abd 100644 --- a/Sources/ImperialGoogle/Standard/Google.swift +++ b/Sources/ImperialGoogle/Standard/Google.swift @@ -10,11 +10,11 @@ public class Google: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try GoogleRouter(callback: callback, completion: completion) + self.router = try GoogleRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialGoogle/Standard/GoogleRouter.swift b/Sources/ImperialGoogle/Standard/GoogleRouter.swift index 56b7051..44436c7 100644 --- a/Sources/ImperialGoogle/Standard/GoogleRouter.swift +++ b/Sources/ImperialGoogle/Standard/GoogleRouter.swift @@ -5,7 +5,7 @@ public class GoogleRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public let accessTokenURL: String = "https://www.googleapis.com/oauth2/v4/token" public let service: OAuthService = .google public let callbackHeaders: HTTPHeaders = { @@ -14,9 +14,9 @@ public class GoogleRouter: FederatedServiceRouter { return headers }() - public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try GoogleAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } @@ -43,7 +43,7 @@ public class GoogleRouter: FederatedServiceRouter { GoogleCallbackBody(code: code, clientId: tokens.clientID, clientSecret: tokens.clientSecret, - redirectURI: callbackURL) + redirectURI: redirectURL) } } diff --git a/Sources/ImperialKeycloak/Keycloak.swift b/Sources/ImperialKeycloak/Keycloak.swift index a5432fa..7191861 100644 --- a/Sources/ImperialKeycloak/Keycloak.swift +++ b/Sources/ImperialKeycloak/Keycloak.swift @@ -10,11 +10,11 @@ public class Keycloak: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.router = try KeycloakRouter(callback: callback, completion: completion) + self.router = try KeycloakRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialKeycloak/KeycloakRouter.swift b/Sources/ImperialKeycloak/KeycloakRouter.swift index e1fc8c5..0c7376a 100644 --- a/Sources/ImperialKeycloak/KeycloakRouter.swift +++ b/Sources/ImperialKeycloak/KeycloakRouter.swift @@ -6,22 +6,22 @@ public class KeycloakRouter: FederatedServiceRouter { public let keycloakTokens: KeycloakAuth public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public let accessTokenURL: String public let service: OAuthService = .keycloak - public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try KeycloakAuth() self.keycloakTokens = self.tokens as! KeycloakAuth self.accessTokenURL = keycloakTokens.accessTokenURL - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } public func authURL(_ request: Request) throws -> String { return "\(keycloakTokens.authURL)/auth?" + "client_id=\(self.tokens.clientID)&" + - "redirect_uri=\(self.callbackURL)&" + + "redirect_uri=\(self.redirectURL)&" + "scope=\(scope.joined(separator: "%20"))&" + "response_type=code" } @@ -30,6 +30,6 @@ public class KeycloakRouter: FederatedServiceRouter { KeycloakCallbackBody(code: code, clientId: tokens.clientID, clientSecret: tokens.clientSecret, - redirectURI: callbackURL) + redirectURI: redirectURL) } } diff --git a/Sources/ImperialMicrosoft/Microsoft.swift b/Sources/ImperialMicrosoft/Microsoft.swift index 5621922..a7f250d 100644 --- a/Sources/ImperialMicrosoft/Microsoft.swift +++ b/Sources/ImperialMicrosoft/Microsoft.swift @@ -10,11 +10,11 @@ public class Microsoft: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String] = [], completion: @escaping (Request, String)throws -> (EventLoopFuture) ) throws { - self.router = try MicrosoftRouter(callback: callback, completion: completion) + self.router = try MicrosoftRouter(redirectURL: redirectURL, completion: completion) self.tokens = self.router.tokens self.router.scope = scope diff --git a/Sources/ImperialMicrosoft/MicrosoftRouter.swift b/Sources/ImperialMicrosoft/MicrosoftRouter.swift index 1d05d6a..13d38f9 100644 --- a/Sources/ImperialMicrosoft/MicrosoftRouter.swift +++ b/Sources/ImperialMicrosoft/MicrosoftRouter.swift @@ -8,18 +8,18 @@ public class MicrosoftRouter: FederatedServiceRouter { public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String)throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public var tenantID: String { Environment.get(MicrosoftRouter.tenantIDEnvKey) ?? "common" } public var accessTokenURL: String { "https://login.microsoftonline.com/\(self.tenantID)/oauth2/v2.0/token" } public let service: OAuthService = .microsoft public let errorKey = "error_description" public required init( - callback: String, + redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { self.tokens = try MicrosoftAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } @@ -48,7 +48,7 @@ public class MicrosoftRouter: FederatedServiceRouter { MicrosoftCallbackBody(code: code, clientId: tokens.clientID, clientSecret: tokens.clientSecret, - redirectURI: callbackURL, + redirectURI: redirectURL, scope: scope.joined(separator: " ")) } diff --git a/Sources/ImperialShopify/Shopify.swift b/Sources/ImperialShopify/Shopify.swift index e377470..7e905d8 100644 --- a/Sources/ImperialShopify/Shopify.swift +++ b/Sources/ImperialShopify/Shopify.swift @@ -12,11 +12,11 @@ public final class Shopify: FederatedService { routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture))?, - callback: String, + redirectURL: String, scope: [String], completion: @escaping (Request, String) throws -> (EventLoopFuture) ) throws { - self.shopifyRouter = try ShopifyRouter(callback: callback, completion: completion) + self.shopifyRouter = try ShopifyRouter(redirectURL: redirectURL, completion: completion) self.shopifyRouter.scope = scope try self.router.configureRoutes( diff --git a/Sources/ImperialShopify/ShopifyRouter.swift b/Sources/ImperialShopify/ShopifyRouter.swift index 5e7f4a3..4809bbf 100644 --- a/Sources/ImperialShopify/ShopifyRouter.swift +++ b/Sources/ImperialShopify/ShopifyRouter.swift @@ -1,17 +1,18 @@ import Vapor public class ShopifyRouter: FederatedServiceRouter { + public let tokens: FederatedServiceTokens public let callbackCompletion: (Request, String) throws -> (EventLoopFuture) public var scope: [String] = [] - public let callbackURL: String + public let redirectURL: String public var accessTokenURL: String = "" public let service: OAuthService = .shopify - required public init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { + required public init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture)) throws { self.tokens = try ShopifyAuth() - self.callbackURL = callback + self.redirectURL = redirectURL self.callbackCompletion = completion } @@ -87,7 +88,7 @@ public class ShopifyRouter: FederatedServiceRouter { private func authURLFrom(_ shop: String, nonce: String) throws -> URL { return URL(string: "https://\(shop)/admin/oauth/authorize?" + "client_id=\(tokens.clientID)&" + "scope=\(scope.joined(separator: ","))&" + - "redirect_uri=\(callbackURL)&" + + "redirect_uri=\(redirectURL)&" + "state=\(nonce)")! }