Skip to content

Commit

Permalink
Change all classes to structs
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Dec 4, 2024
1 parent e36ae31 commit 70f39d0
Show file tree
Hide file tree
Showing 29 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions Sources/ImperialAuth0/Auth0.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Auth0: FederatedService {
public struct Auth0: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialAuth0/Auth0Router.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Vapor

final public class Auth0Router: FederatedServiceRouter {
public struct Auth0Router: FederatedServiceRouter {
public let baseURL: String
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
Expand All @@ -15,7 +15,7 @@ final public class Auth0Router: FederatedServiceRouter {
return self.baseURL.finished(with: "/") + path
}

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
let auth = try Auth0Auth()
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialCore/FederatedService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import Vapor
/// import ImperialCore
/// import Vapor
///
/// public class Service: FederatedService {
/// public struct Service: FederatedService {
/// public var tokens: any FederatedServiceTokens
/// public var router: any FederatedServiceRouter
///
/// @discardableResult
/// public required init(
/// public init(
/// routes: some RoutesBuilder,
/// authenticate: String,
/// authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
2 changes: 1 addition & 1 deletion Sources/ImperialCore/FederatedServiceRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Vapor
/// Defines a type that implements the routing to get an access token from an OAuth provider.
/// See implementations in the `Services/(Google|GitHub)/$0Router.swift` files
public protocol FederatedServiceRouter: Sendable {
/// A class that gets the client ID and secret from environment variables.
/// An object that gets the client ID and secret from environment variables.
var tokens: any FederatedServiceTokens { get }

/// The callback that is fired after the access token is fetched from the OAuth provider.
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialDeviantArt/DeviantArt.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class DeviantArt: FederatedService {
public struct DeviantArt: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialDeviantArt/DeviantArtRouter.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Foundation
import Vapor

final public class DeviantArtRouter: FederatedServiceRouter {
public struct DeviantArtRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
public let callbackURL: String
public let accessTokenURL: String = "https://www.deviantart.com/oauth2/token"

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
self.tokens = try DeviantArtAuth()
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialDiscord/Discord.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Discord: FederatedService {
public struct Discord: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialDiscord/DiscordRouter.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Foundation
import Vapor

final public class DiscordRouter: FederatedServiceRouter {
public struct DiscordRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
public let callbackURL: String
public let accessTokenURL: String = "https://discord.com/api/oauth2/token"
public let callbackHeaders = HTTPHeaders([("Content-Type", "application/x-www-form-urlencoded")])

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
self.tokens = try DiscordAuth()
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialDropbox/Dropbox.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Dropbox: FederatedService {
public struct Dropbox: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialDropbox/DropboxRouter.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Vapor

final public class DropboxRouter: FederatedServiceRouter {
public struct DropboxRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
Expand All @@ -15,7 +15,7 @@ final public class DropboxRouter: FederatedServiceRouter {
return headers
}

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
self.tokens = try DropboxAuth()
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialFacebook/Facebook.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Facebook: FederatedService {
public struct Facebook: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialFacebook/FacebookRouter.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Vapor

final public class FacebookRouter: FederatedServiceRouter {
public struct FacebookRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
Expand All @@ -27,7 +27,7 @@ final public class FacebookRouter: FederatedServiceRouter {
return url.absoluteString
}

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
self.tokens = try FacebookAuth()
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialGitHub/GitHub.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class GitHub: FederatedService {
public struct GitHub: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
8 changes: 4 additions & 4 deletions Sources/ImperialGitHub/GitHubRouter.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Vapor

final public class GitHubRouter: FederatedServiceRouter {
public struct GitHubRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
Expand All @@ -13,7 +13,7 @@ final public class GitHubRouter: FederatedServiceRouter {
return headers
}()

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
self.tokens = try GitHubAuth()
Expand All @@ -23,7 +23,6 @@ final public class GitHubRouter: FederatedServiceRouter {
}

public func authURL(_ request: Request) throws -> String {

var components = URLComponents()
components.scheme = "https"
components.host = "github.com"
Expand All @@ -44,7 +43,8 @@ final public class GitHubRouter: FederatedServiceRouter {
GitHubCallbackBody(
clientId: tokens.clientID,
clientSecret: tokens.clientSecret,
code: code)
code: code
)
}

}
4 changes: 2 additions & 2 deletions Sources/ImperialGitlab/Gitlab.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Gitlab: FederatedService {
public struct Gitlab: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialGitlab/GitlabRouter.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Foundation
import Vapor

final public class GitlabRouter: FederatedServiceRouter {
public struct GitlabRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
public let callbackURL: String
public let accessTokenURL: String = "https://gitlab.com/oauth/token"

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
self.tokens = try GitlabAuth()
Expand Down
2 changes: 1 addition & 1 deletion Sources/ImperialGoogle/JWT/GoogleJWTRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
import JWTKit
import Vapor

public final class GoogleJWTRouter: FederatedServiceRouter {
public struct GoogleJWTRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialGoogle/Standard/Google.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Google: FederatedService {
public struct Google: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialGoogle/Standard/GoogleRouter.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation
import Vapor

final public class GoogleRouter: FederatedServiceRouter {
public struct GoogleRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
Expand All @@ -13,7 +13,7 @@ final public class GoogleRouter: FederatedServiceRouter {
return headers
}()

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
self.tokens = try GoogleAuth()
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialImgur/Imgur.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Imgur: FederatedService {
public struct Imgur: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialImgur/ImgurRouter.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import Foundation
import Vapor

final public class ImgurRouter: FederatedServiceRouter {
public struct ImgurRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
public let callbackURL: String
public let accessTokenURL: String = "https://api.imgur.com/oauth2/token"

public required init(
public init(
callback: String,
scope: [String],
completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialKeycloak/Keycloak.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Keycloak: FederatedService {
public struct Keycloak: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialKeycloak/KeycloakRouter.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Foundation
import Vapor

final public class KeycloakRouter: FederatedServiceRouter {
public struct KeycloakRouter: FederatedServiceRouter {
public let tokens: any FederatedServiceTokens
public let callbackCompletion: @Sendable (Request, String) async throws -> any AsyncResponseEncodable
public let scope: [String]
public let callbackURL: String
public let accessTokenURL: String
let authURL: String // This is an additional property of `tokens` that is not in the protocol

public required init(
public init(
callback: String, scope: [String], completion: @escaping @Sendable (Request, String) async throws -> some AsyncResponseEncodable
) throws {
self.tokens = try KeycloakAuth()
Expand Down
4 changes: 2 additions & 2 deletions Sources/ImperialMicrosoft/Microsoft.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
@_exported import ImperialCore
import Vapor

final public class Microsoft: FederatedService {
public struct Microsoft: FederatedService {
public let tokens: any FederatedServiceTokens
public let router: any FederatedServiceRouter

@discardableResult
public required init(
public init(
routes: some RoutesBuilder,
authenticate: String,
authenticateCallback: (@Sendable (Request) async throws -> Void)?,
Expand Down
Loading

0 comments on commit 70f39d0

Please sign in to comment.