Skip to content

Commit

Permalink
first draft rename
Browse files Browse the repository at this point in the history
Signed-off-by: wibe <[email protected]>
  • Loading branch information
wibed committed Mar 12, 2024
1 parent aaa23b9 commit 6cee084
Show file tree
Hide file tree
Showing 29 changed files with 96 additions and 96 deletions.
10 changes: 5 additions & 5 deletions Sources/Imperial/Services/DeviantArt/DeviantArtRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ public class DeviantArtRouter: FederatedServiceRouter {
public let tokens: FederatedServiceTokens
public let callbackCompletion: (Request, String)throws -> (Future<ResponseEncodable>)
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<ResponseEncodable>)) throws {
public required init(redirectURL: String, completion: @escaping (Request, String)throws -> (Future<ResponseEncodable>)) throws {
self.tokens = try DeviantArtAuth()
self.callbackURL = callback
self.redirectURL = redirectURL
self.callbackCompletion = completion
}

Expand All @@ -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"
}

Expand All @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions Sources/Imperial/Services/Imgur/ImgurRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ public class ImgurRouter: FederatedServiceRouter {
public let tokens: FederatedServiceTokens
public let callbackCompletion: (Request, String)throws -> (Future<ResponseEncodable>)
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<ResponseEncodable>)) throws {
public required init(redirectURL: String, completion: @escaping (Request, String)throws -> (Future<ResponseEncodable>)) throws {
self.tokens = try ImgurAuth()
self.callbackURL = callback
self.redirectURL = redirectURL
self.callbackCompletion = completion
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/Imperial/Services/Microsoft/MicrosoftRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ public class MicrosoftRouter: FederatedServiceRouter {
public let tokens: FederatedServiceTokens
public let callbackCompletion: (Request, String)throws -> (Future<ResponseEncodable>)
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<ResponseEncodable>)
) throws {
self.tokens = try MicrosoftAuth()
self.callbackURL = callback
self.redirectURL = redirectURL
self.callbackCompletion = completion
}

public func authURL(_ request: Request) throws -> String {
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"
Expand All @@ -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")
)

Expand Down
10 changes: 5 additions & 5 deletions Sources/Imperial/Services/Mixcloud/MixcloudRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ public class MixcloudRouter: FederatedServiceRouter {
public let tokens: FederatedServiceTokens
public let callbackCompletion: (Request, String)throws -> (Future<ResponseEncodable>)
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<ResponseEncodable>)) throws {
public required init(redirectURL: String, completion: @escaping (Request, String)throws -> (Future<ResponseEncodable>)) 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<String> {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialAuth0/Auth0.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class Auth0: FederatedService {
routes: RoutesBuilder,
authenticate: String,
authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?,
callback: String,
redirectURL: String,
scope: [String] = [],
completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
) 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
Expand Down
10 changes: 5 additions & 5 deletions Sources/ImperialAuth0/Auth0Router.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Auth0Router: FederatedServiceRouter {
public let callbackCompletion: (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
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")])
Expand All @@ -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<ResponseEncodable>)) throws {
public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) 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
}

Expand All @@ -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
Expand All @@ -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)
}
}
8 changes: 4 additions & 4 deletions Sources/ImperialCore/Routing/FederatedServiceRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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<ResponseEncodable>)) throws
init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws

/// Configures the `authenticate` and `callback` routes with the droplet.
///
Expand Down Expand Up @@ -78,7 +78,7 @@ extension FederatedServiceRouter {
public var callbackHeaders: HTTPHeaders { [:] }

public func configureRoutes(withAuthURL authURL: String, authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?, on router: RoutesBuilder) throws {
router.get(callbackURL.pathComponents, use: callback)
router.get(redirectURL.pathComponents, use: callback)
router.get(authURL.pathComponents) { req -> EventLoopFuture<Response> in
let redirect: Response = req.redirect(to: try self.authURL(req))
guard let authenticateCallback = authenticateCallback else {
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions Sources/ImperialCore/ServiceRegister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ extension RoutesBuilder {
from provider: OAuthProvider.Type,
authenticate authUrl: String,
authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))? = nil,
callback: String,
redirectURL: String,
scope: [String] = [],
completion: @escaping (Request, String) throws -> EventLoopFuture<ResponseEncodable>
) throws where OAuthProvider: FederatedService {
_ = try OAuthProvider(
routes: self,
authenticate: authUrl,
authenticateCallback: authenticateCallback,
callback: callback,
redirectURL: redirectURL,
scope: scope,
completion: completion
)
Expand All @@ -47,12 +47,12 @@ extension RoutesBuilder {
from provider: OAuthProvider.Type,
authenticate authUrl: String,
authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))? = 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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ImperialCore/Services/FederatedService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Void>))?, callback: String, scope: [String], completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws
init(routes: RoutesBuilder, authenticate: String, authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?, redirectURL: String, scope: [String], completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws
}
4 changes: 2 additions & 2 deletions Sources/ImperialDiscord/Discord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class Discord: FederatedService {
routes: RoutesBuilder,
authenticate: String,
authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?,
callback: String,
redirectURL: String,
scope: [String] = [],
completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
) 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
Expand Down
6 changes: 3 additions & 3 deletions Sources/ImperialDiscord/DiscordRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ public class DiscordRouter: FederatedServiceRouter {
public let tokens: FederatedServiceTokens
public let callbackCompletion: (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
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<ResponseEncodable>)) throws {
public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws {
self.tokens = try DiscordAuth()
self.callbackURL = callback
self.redirectURL = redirectURL
self.callbackCompletion = completion
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialDropbox/Dropbox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class Dropbox: FederatedService {
routes: RoutesBuilder,
authenticate: String,
authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?,
callback: String,
redirectURL: String,
scope: [String] = [],
completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
) 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
Expand Down
9 changes: 4 additions & 5 deletions Sources/ImperialDropbox/DropboxRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class DropboxRouter: FederatedServiceRouter {
public let tokens: FederatedServiceTokens
public let callbackCompletion: (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
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 {
Expand All @@ -17,9 +17,9 @@ public class DropboxRouter: FederatedServiceRouter {

public let service: OAuthService = .dropbox

public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws {
public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws {
self.tokens = try DropboxAuth()
self.callbackURL = callback
self.redirectURL = redirectURL
self.callbackCompletion = completion
}

Expand All @@ -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)
}

}
4 changes: 2 additions & 2 deletions Sources/ImperialFacebook/Facebook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class Facebook: FederatedService {
routes: RoutesBuilder,
authenticate: String,
authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?,
callback: String,
redirectURL: String,
scope: [String] = [],
completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
) 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
Expand Down
8 changes: 4 additions & 4 deletions Sources/ImperialFacebook/FacebookRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class FacebookRouter: FederatedServiceRouter {
public let tokens: FederatedServiceTokens
public let callbackCompletion: (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
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

Expand All @@ -29,17 +29,17 @@ public class FacebookRouter: FederatedServiceRouter {
return url.absoluteString
}

public required init(callback: String, completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws {
public required init(redirectURL: String, completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)) throws {
self.tokens = try FacebookAuth()
self.callbackURL = callback
self.redirectURL = redirectURL
self.callbackCompletion = completion
}

public func callbackBody(with code: String) -> ResponseEncodable {
FacebookCallbackBody(code: code,
clientId: tokens.clientID,
clientSecret: tokens.clientSecret,
redirectURI: callbackURL)
redirectURI: redirectURL)
}

}
4 changes: 2 additions & 2 deletions Sources/ImperialGitHub/GitHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class GitHub: FederatedService {
routes: RoutesBuilder,
authenticate: String,
authenticateCallback: ((Request) throws -> (EventLoopFuture<Void>))?,
callback: String,
redirectURL: String,
scope: [String] = [],
completion: @escaping (Request, String) throws -> (EventLoopFuture<ResponseEncodable>)
) 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
Expand Down
Loading

0 comments on commit 6cee084

Please sign in to comment.