From 129926a4275d763dcba6a600883bec62d976222b Mon Sep 17 00:00:00 2001 From: metalurgical <97008724+metalurgical@users.noreply.github.com> Date: Mon, 29 Jul 2024 22:58:25 +0200 Subject: [PATCH] update: visibility and initial inline documentation --- Package.resolved | 2 +- Package.swift | 3 +- Sources/CustomAuth/Common/State.swift | 2 +- Sources/CustomAuth/CustomAuth.swift | 52 +++++++++++++++++++ .../CustomAuth/Extension/Data+extension.swift | 2 +- .../Extension/String+extension.swift | 2 +- .../Extension/URLComponents+extension.swift | 2 +- .../Handlers/AuthenticationManager.swift | 2 +- .../Handlers/DiscordLoginHandler.swift | 4 +- .../Handlers/FacebookLoginHandler.swift | 8 +-- .../Handlers/GoogleLoginHandler.swift | 4 +- .../CustomAuth/Handlers/HandlerFactory.swift | 2 +- .../CustomAuth/Handlers/JWTLoginHandler.swift | 4 +- .../Handlers/MockLoginHandler.swift | 2 +- .../Handlers/PasswordlessLoginHandler.swift | 2 +- .../Protocol/AbstractLoginHandler.swift | 2 +- .../Protocol/CreateHandlerParams.swift | 2 +- .../Handlers/Protocol/ILoginHandler.swift | 2 +- .../Handlers/RedditLoginHandler.swift | 4 +- .../Handlers/TwitchLoginHandler.swift | 6 +-- Sources/CustomAuth/Helpers/Common.swift | 4 +- 21 files changed, 82 insertions(+), 31 deletions(-) diff --git a/Package.resolved b/Package.resolved index 28b458e..c12425b 100644 --- a/Package.resolved +++ b/Package.resolved @@ -59,7 +59,7 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/torusresearch/torus-utils-swift.git", "state" : { - "revision" : "7788752bed699b3d34e78c2c51174f814d02610b", + "revision" : "303dc2cf41db7c10f769855edad0e717ced2d554", "version" : "9.0.0" } } diff --git a/Package.swift b/Package.swift index 6efecbb..00a2b64 100644 --- a/Package.swift +++ b/Package.swift @@ -16,14 +16,13 @@ let package = Package( dependencies: [ .package(url: "https://github.com/torusresearch/torus-utils-swift.git", from: "9.0.0"), .package(url: "https://github.com/auth0/JWTDecode.swift.git", from: "3.1.0"), - .package(url: "https://github.com/tkey/curvelib.swift", from: "1.0.1"), // NB: jwt-kit may only be a test dependency or it will break cocoapods support .package(url: "https://github.com/vapor/jwt-kit.git", from: "4.13.0"), ], targets: [ .target( name: "CustomAuth", - dependencies: [.product(name: "JWTDecode", package: "JWTDecode.swift"), .product(name: "curveSecp256k1", package: "curvelib.swift"), .product(name: "TorusUtils", package: "torus-utils-swift")]), + dependencies: [.product(name: "JWTDecode", package: "JWTDecode.swift"), .product(name: "TorusUtils", package: "torus-utils-swift")]), .testTarget( name: "CustomAuthTests", dependencies: ["CustomAuth", .product(name: "JWTKit", package: "jwt-kit")]) diff --git a/Sources/CustomAuth/Common/State.swift b/Sources/CustomAuth/Common/State.swift index 36c6d07..fdf1d76 100644 --- a/Sources/CustomAuth/Common/State.swift +++ b/Sources/CustomAuth/Common/State.swift @@ -1,6 +1,6 @@ import Foundation -public class State: Codable { +internal class State: Codable { public var customState: TorusGenericContainer? public var instanceId: String public var verifier: String diff --git a/Sources/CustomAuth/CustomAuth.swift b/Sources/CustomAuth/CustomAuth.swift index 943088c..e658c68 100644 --- a/Sources/CustomAuth/CustomAuth.swift +++ b/Sources/CustomAuth/CustomAuth.swift @@ -15,6 +15,14 @@ public class CustomAuth { public let nodeDetailManager: NodeDetailManager + /// Initializes CustomAuth with the provided options + /// + /// - Parameters: + /// - params: `CustomAuthArgs` + /// + /// - Returns: `CustomAuth` + /// + /// - Throws: `CASDKError.invalidCallbackURLScheme`, `TorusUtilError.invalidInput` public init(config: CustomAuthArgs) throws { if URL(string: config.urlScheme)?.scheme == nil { throw CASDKError.invalidCallbackURLScheme @@ -37,6 +45,14 @@ public class CustomAuth { torus.setApiKey(apiKey: config.apiKey ?? "") } + /// Initiates a login using a single verifier + /// + /// - Parameters: + /// - params: `SingleLoginParams` + /// + /// - Returns: `TorusLoginResponse` + /// + /// - Throws: `CASDKError`, `TorusUtilError` public func triggerLogin(args: SingleLoginParams) async throws -> TorusLoginResponse { let loginHandler = try HandlerFactory.createHandler(params: CreateHandlerParams(typeOfLogin: args.typeOfLogin, verifier: args.verifier, clientId: args.clientId, urlScheme: config.urlScheme, redirectURL: args.redirectURL, jwtParams: args.jwtParams, customState: args.customState)) @@ -62,6 +78,14 @@ public class CustomAuth { return TorusLoginResponse(singleVerifierResponse: TorusSingleVerifierResponse(userInfo: returnedInfo, loginResponse: loginParams), torusKey: torusKey) } + /// Initiates a login using a aggregate verifier + /// + /// - Parameters: + /// - params: `AggregateLoginParams` + /// + /// - Returns: `TorusAggregateLoginResponse` + /// + /// - Throws: `CASDKError`, `TorusUtilError` public func triggerAggregateLogin(args: AggregateLoginParams) async throws -> TorusAggregateLoginResponse { if args.subVerifierDetailsArray.isEmpty { throw CASDKError.invalidParameters @@ -123,6 +147,14 @@ public class CustomAuth { return TorusAggregateLoginResponse(torusAggregateVerifierResponse: aggregateVerifierResponses, torusKey: aggregateTorusKey) } + /// Initiates a login using a hybrid verifier + /// + /// - Parameters: + /// - params: `HybridAggregateLoginParams` + /// + /// - Returns: `TorusHybridAggregateLoginResponse` + /// + /// - Throws: `CASDKError`, `TorusUtilError` public func triggerHybridAggregateLogin(args: HybridAggregateLoginParams) async throws -> TorusHybridAggregateLoginResponse { if args.aggregateLoginParams.subVerifierDetailsArray.isEmpty { throw CASDKError.invalidParameters @@ -177,12 +209,32 @@ public class CustomAuth { return TorusHybridAggregateLoginResponse(singleLogin: aggregateLogin, aggregateLogins: [aggregateTorusKey]) } + /// Retrieves the key details + /// + /// - Parameters: + /// - verifier: `String` + /// - verifierParams: `VerifierParams` + /// - idToken: `String` + /// + /// - Returns: `TorusKey` + /// + /// - Throws: `CASDKError`, `TorusUtilError`, `FetchNodeError` func getTorusKey(verifier: String, verifierParams: VerifierParams, idToken: String) async throws -> TorusKey { let nodeDetails = try await nodeDetailManager.getNodeDetails(verifier: verifier, verifierID: verifierParams.verifier_id) return try await torus.retrieveShares(endpoints: nodeDetails.getTorusNodeEndpoints(), verifier: verifier, verifierParams: verifierParams, idToken: idToken) } + /// Retrieves the aggregate key details + /// + /// - Parameters: + /// - verifier: `String` + /// - verifierParams: `VerifierParams` + /// - subVerifierInfoArray: `TorusSubVerifierInfo` + /// + /// - Returns: `TorusKey` + /// + /// - Throws: `CASDKError`, `TorusUtilError`, `FetchNodeError` func getAggregateTorusKey(verifier: String, verifierParams: VerifierParams, subVerifierInfoArray: [TorusSubVerifierInfo]) async throws -> TorusKey { let nodeDetails = try await nodeDetailManager.getNodeDetails(verifier: verifier, verifierID: verifierParams.verifier_id) diff --git a/Sources/CustomAuth/Extension/Data+extension.swift b/Sources/CustomAuth/Extension/Data+extension.swift index 2b62938..6b50f81 100644 --- a/Sources/CustomAuth/Extension/Data+extension.swift +++ b/Sources/CustomAuth/Extension/Data+extension.swift @@ -1,6 +1,6 @@ import Foundation -extension Data { +internal extension Data { func toBase64URL() -> String { var result = base64EncodedString() result = result.replacingOccurrences(of: "+", with: "-") diff --git a/Sources/CustomAuth/Extension/String+extension.swift b/Sources/CustomAuth/Extension/String+extension.swift index afddc9f..989cc2e 100644 --- a/Sources/CustomAuth/Extension/String+extension.swift +++ b/Sources/CustomAuth/Extension/String+extension.swift @@ -1,6 +1,6 @@ import Foundation -extension String { +internal extension String { func fromBase64URL() throws -> String { var base64 = self base64 = base64.replacingOccurrences(of: "-", with: "+") diff --git a/Sources/CustomAuth/Extension/URLComponents+extension.swift b/Sources/CustomAuth/Extension/URLComponents+extension.swift index f223d36..c5edd08 100644 --- a/Sources/CustomAuth/Extension/URLComponents+extension.swift +++ b/Sources/CustomAuth/Extension/URLComponents+extension.swift @@ -1,6 +1,6 @@ import Foundation -extension URLComponents { +internal extension URLComponents { mutating func setQueryItems(with parameters: [String: String]) { queryItems = parameters.map { URLQueryItem(name: $0.key, value: $0.value) } } diff --git a/Sources/CustomAuth/Handlers/AuthenticationManager.swift b/Sources/CustomAuth/Handlers/AuthenticationManager.swift index 4fb3709..dce0268 100644 --- a/Sources/CustomAuth/Handlers/AuthenticationManager.swift +++ b/Sources/CustomAuth/Handlers/AuthenticationManager.swift @@ -5,7 +5,7 @@ import AuthenticationServices import UIKit #endif -public class AuthenticationManager: NSObject, ASWebAuthenticationPresentationContextProviding { +internal class AuthenticationManager: NSObject, ASWebAuthenticationPresentationContextProviding { public func presentationAnchor(for session: ASWebAuthenticationSession) -> ASPresentationAnchor { var window: ASPresentationAnchor? #if os(macOS) diff --git a/Sources/CustomAuth/Handlers/DiscordLoginHandler.swift b/Sources/CustomAuth/Handlers/DiscordLoginHandler.swift index b0e0aae..d733793 100644 --- a/Sources/CustomAuth/Handlers/DiscordLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/DiscordLoginHandler.swift @@ -1,6 +1,6 @@ import Foundation -class DiscordInfo: Codable { +internal class DiscordInfo: Codable { public var id: String public var username: String public var avatar: String? @@ -8,7 +8,7 @@ class DiscordInfo: Codable { public var email: String } -class DiscordLoginHandler: AbstractLoginHandler { +internal class DiscordLoginHandler: AbstractLoginHandler { private var response_type: String = "token" private var scope: String = "identify email" private var prompt: String = "none" diff --git a/Sources/CustomAuth/Handlers/FacebookLoginHandler.swift b/Sources/CustomAuth/Handlers/FacebookLoginHandler.swift index 9212293..0081886 100644 --- a/Sources/CustomAuth/Handlers/FacebookLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/FacebookLoginHandler.swift @@ -1,21 +1,21 @@ import Foundation -class FacebookPictureData: Codable { +internal class FacebookPictureData: Codable { public var url: String } -class FacebookPicture: Codable { +internal class FacebookPicture: Codable { public var data: FacebookPictureData } -class FacebookInfo: Codable { +internal class FacebookInfo: Codable { public var id: String public var name: String public var picture: FacebookPicture public var email: String } -class FacebookLoginHandler: AbstractLoginHandler { +internal class FacebookLoginHandler: AbstractLoginHandler { private var response_type: String = "token" private var scope: String = "public_profile email" diff --git a/Sources/CustomAuth/Handlers/GoogleLoginHandler.swift b/Sources/CustomAuth/Handlers/GoogleLoginHandler.swift index 4ebe580..c733582 100644 --- a/Sources/CustomAuth/Handlers/GoogleLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/GoogleLoginHandler.swift @@ -1,12 +1,12 @@ import Foundation -class GoogleInfo: Codable { +internal class GoogleInfo: Codable { public var name: String public var picture: String public var email: String } -class GoogleLoginHandler: AbstractLoginHandler { +internal class GoogleLoginHandler: AbstractLoginHandler { private var response_type: String = "token id_token" private var scope: String = "profile email openid" private var prompt: String = "select_account" diff --git a/Sources/CustomAuth/Handlers/HandlerFactory.swift b/Sources/CustomAuth/Handlers/HandlerFactory.swift index 5c258d9..aee28ed 100644 --- a/Sources/CustomAuth/Handlers/HandlerFactory.swift +++ b/Sources/CustomAuth/Handlers/HandlerFactory.swift @@ -1,6 +1,6 @@ import Foundation -public class HandlerFactory { +internal class HandlerFactory { static func createHandler( params: CreateHandlerParams ) throws -> ILoginHandler { diff --git a/Sources/CustomAuth/Handlers/JWTLoginHandler.swift b/Sources/CustomAuth/Handlers/JWTLoginHandler.swift index 92c65d4..0599e02 100644 --- a/Sources/CustomAuth/Handlers/JWTLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/JWTLoginHandler.swift @@ -1,7 +1,7 @@ import Foundation import JWTDecode -public class Auth0UserInfo: Codable { +internal class Auth0UserInfo: Codable { public let picture: String public let email: String public let name: String @@ -17,7 +17,7 @@ public class Auth0UserInfo: Codable { } } -class JWTLoginHandler: AbstractLoginHandler { +internal class JWTLoginHandler: AbstractLoginHandler { private var response_type: String = "token id_token" private var scope: String = "openid profile email" private var prompt: String = "login" diff --git a/Sources/CustomAuth/Handlers/MockLoginHandler.swift b/Sources/CustomAuth/Handlers/MockLoginHandler.swift index c079edb..df17a0f 100644 --- a/Sources/CustomAuth/Handlers/MockLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/MockLoginHandler.swift @@ -1,7 +1,7 @@ import Foundation import JWTDecode -class MockLoginHandler: AbstractLoginHandler { +internal class MockLoginHandler: AbstractLoginHandler { override public init(clientId: String, verifier: String, urlScheme: String, redirectURL: String, typeOfLogin: LoginType, jwtParams: Auth0ClientOptions? = nil, customState: TorusGenericContainer? = nil) throws { try super.init(clientId: clientId, verifier: verifier, urlScheme: urlScheme, redirectURL: redirectURL, typeOfLogin: typeOfLogin, jwtParams: jwtParams, customState: customState) try setFinalUrl() diff --git a/Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift b/Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift index c38d9d4..2176c18 100644 --- a/Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/PasswordlessLoginHandler.swift @@ -1,7 +1,7 @@ import Foundation import JWTDecode -class PasswordlessLoginHandler: AbstractLoginHandler { +internal class PasswordlessLoginHandler: AbstractLoginHandler { private var response_type: String = "token id_token" private var scope: String = "openid profile email" private var prompt: String = "login" diff --git a/Sources/CustomAuth/Handlers/Protocol/AbstractLoginHandler.swift b/Sources/CustomAuth/Handlers/Protocol/AbstractLoginHandler.swift index 4bca9c4..464fd7f 100644 --- a/Sources/CustomAuth/Handlers/Protocol/AbstractLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/Protocol/AbstractLoginHandler.swift @@ -3,7 +3,7 @@ import Foundation import curveSecp256k1 #endif -public class AbstractLoginHandler: ILoginHandler { +internal class AbstractLoginHandler: ILoginHandler { public var clientId: String public var nonce: String diff --git a/Sources/CustomAuth/Handlers/Protocol/CreateHandlerParams.swift b/Sources/CustomAuth/Handlers/Protocol/CreateHandlerParams.swift index 9e8da0d..5db8380 100644 --- a/Sources/CustomAuth/Handlers/Protocol/CreateHandlerParams.swift +++ b/Sources/CustomAuth/Handlers/Protocol/CreateHandlerParams.swift @@ -1,6 +1,6 @@ import Foundation -public class CreateHandlerParams: Codable { +internal class CreateHandlerParams: Codable { public let typeOfLogin: LoginType public let verifier: String public let clientId: String diff --git a/Sources/CustomAuth/Handlers/Protocol/ILoginHandler.swift b/Sources/CustomAuth/Handlers/Protocol/ILoginHandler.swift index 010e721..3201741 100644 --- a/Sources/CustomAuth/Handlers/Protocol/ILoginHandler.swift +++ b/Sources/CustomAuth/Handlers/Protocol/ILoginHandler.swift @@ -1,6 +1,6 @@ import Foundation -public protocol ILoginHandler { +internal protocol ILoginHandler { var clientId: String { get set } var nonce: String { get set } var finalUrl: URLComponents { get set } diff --git a/Sources/CustomAuth/Handlers/RedditLoginHandler.swift b/Sources/CustomAuth/Handlers/RedditLoginHandler.swift index 9df1709..85ab16e 100644 --- a/Sources/CustomAuth/Handlers/RedditLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/RedditLoginHandler.swift @@ -1,11 +1,11 @@ import Foundation -class RedditInfo: Codable { +internal class RedditInfo: Codable { public var name: String public var icon_image: String? } -class RedditLoginHandler: AbstractLoginHandler { +internal class RedditLoginHandler: AbstractLoginHandler { private var response_type: String = "token" private var scope: String = "identity" diff --git a/Sources/CustomAuth/Handlers/TwitchLoginHandler.swift b/Sources/CustomAuth/Handlers/TwitchLoginHandler.swift index bd1f3f9..1723669 100644 --- a/Sources/CustomAuth/Handlers/TwitchLoginHandler.swift +++ b/Sources/CustomAuth/Handlers/TwitchLoginHandler.swift @@ -1,17 +1,17 @@ import Foundation -class TwitchInfo: Codable { +internal class TwitchInfo: Codable { public var id: String public var email: String? public var display_name: String public var profile_image_url: String } -class TwitchRootInfo: Codable { +internal class TwitchRootInfo: Codable { public var data: [TwitchInfo] } -class TwitchLoginHandler: AbstractLoginHandler { +internal class TwitchLoginHandler: AbstractLoginHandler { private var response_type: String = "token" private var scope: String = "user:read:email" diff --git a/Sources/CustomAuth/Helpers/Common.swift b/Sources/CustomAuth/Helpers/Common.swift index 350fb89..2915de4 100644 --- a/Sources/CustomAuth/Helpers/Common.swift +++ b/Sources/CustomAuth/Helpers/Common.swift @@ -1,6 +1,6 @@ import Foundation -func loginToConnection(loginType: LoginType) -> String { +internal func loginToConnection(loginType: LoginType) -> String { switch loginType { case .apple: break case .google: break @@ -19,7 +19,7 @@ func loginToConnection(loginType: LoginType) -> String { return loginType.rawValue } -func getVerifierId( +internal func getVerifierId( userInfo: Auth0UserInfo, typeOfLogin: LoginType, verifierIdField: String? = nil,