Skip to content

Commit

Permalink
Merge branch 'main' into PSG-4349-ghworkflows
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycpadilla committed Sep 17, 2024
2 parents 9d85f52 + 987b5e5 commit bb7a94a
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AuthenticationServices

@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
extension ASAuthorizationPublicKeyCredentialAssertion {

/// Converts assertion credential into a handshake response formatted for Passage webauthn finish request.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AuthenticationServices

@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
extension ASAuthorizationPublicKeyCredentialRegistration {

/// Converts registration credential into a handshake response formatted for Passage webauthn
Expand Down
3 changes: 2 additions & 1 deletion Sources/Passage/generated/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.gitignore
.openapi-generator-ignore
.swiftformat
Cartfile
OpenAPIClient.podspec
Expand Down Expand Up @@ -39,6 +38,7 @@ OpenAPIClient/Classes/OpenAPIs/Models/AuthenticateWebAuthnStartWithTransactionRe
OpenAPIClient/Classes/OpenAPIs/Models/AuthenticatorAttachment.swift
OpenAPIClient/Classes/OpenAPIs/Models/CreatePasskeyReadinessRequest.swift
OpenAPIClient/Classes/OpenAPIs/Models/CreateUserParams.swift
OpenAPIClient/Classes/OpenAPIs/Models/CreateUserResponse.swift
OpenAPIClient/Classes/OpenAPIs/Models/Credential.swift
OpenAPIClient/Classes/OpenAPIs/Models/CredentialAssertionChallenge.swift
OpenAPIClient/Classes/OpenAPIs/Models/CredentialAssertionResponse.swift
Expand Down Expand Up @@ -145,6 +145,7 @@ docs/AuthenticateWebAuthnStartWithTransactionResponse.md
docs/AuthenticatorAttachment.md
docs/CreatePasskeyReadinessRequest.md
docs/CreateUserParams.md
docs/CreateUserResponse.md
docs/Credential.md
docs/CredentialAssertionChallenge.md
docs/CredentialAssertionResponse.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ open class UsersAPI {

- parameter appId: (path) App ID
- parameter createUserParams: (body) user options
- returns: UserResponse
- returns: CreateUserResponse
*/
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
open class func createUser(appId: String, createUserParams: CreateUserParams) async throws -> UserResponse {
open class func createUser(appId: String, createUserParams: CreateUserParams) async throws -> CreateUserResponse {
return try await createUserWithRequestBuilder(appId: appId, createUserParams: createUserParams).execute().body
}

Expand All @@ -74,9 +74,9 @@ open class UsersAPI {
- Create a user
- parameter appId: (path) App ID
- parameter createUserParams: (body) user options
- returns: RequestBuilder<UserResponse>
- returns: RequestBuilder<CreateUserResponse>
*/
open class func createUserWithRequestBuilder(appId: String, createUserParams: CreateUserParams) -> RequestBuilder<UserResponse> {
open class func createUserWithRequestBuilder(appId: String, createUserParams: CreateUserParams) -> RequestBuilder<CreateUserResponse> {
var localVariablePath = "/apps/{app_id}/users"
let appIdPreEscape = "\(APIHelper.mapValueToPathItem(appId))"
let appIdPostEscape = appIdPreEscape.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? ""
Expand All @@ -92,7 +92,7 @@ open class UsersAPI {

let localVariableHeaderParameters = APIHelper.rejectNilHeaders(localVariableNillableHeaders)

let localVariableRequestBuilder: RequestBuilder<UserResponse>.Type = OpenAPIClientAPI.requestBuilderFactory.getBuilder()
let localVariableRequestBuilder: RequestBuilder<CreateUserResponse>.Type = OpenAPIClientAPI.requestBuilderFactory.getBuilder()

return localVariableRequestBuilder.init(method: "POST", URLString: (localVariableUrlComponents?.string ?? localVariableURLString), parameters: localVariableParameters, headers: localVariableHeaderParameters, requiresAuthentication: false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,6 @@ extension KeyedEncodingContainerProtocol {
}
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
if let value = value {
try encode(value, forKey: key)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// CreateUserResponse.swift
//
// Generated by openapi-generator
// https://openapi-generator.tech
//

import Foundation
#if canImport(AnyCodable)
import AnyCodable
#endif

public struct CreateUserResponse: Codable, JSONEncodable, Hashable {

public var user: User

public init(user: User) {
self.user = user
}

public enum CodingKeys: String, CodingKey, CaseIterable {
case user
}

// Encodable protocol methods

public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(user, forKey: .user)
}
}

1 change: 1 addition & 0 deletions Sources/Passage/generated/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Class | Method | HTTP request | Description
- [AuthenticatorAttachment](docs/AuthenticatorAttachment.md)
- [CreatePasskeyReadinessRequest](docs/CreatePasskeyReadinessRequest.md)
- [CreateUserParams](docs/CreateUserParams.md)
- [CreateUserResponse](docs/CreateUserResponse.md)
- [Credential](docs/Credential.md)
- [CredentialAssertionChallenge](docs/CredentialAssertionChallenge.md)
- [CredentialAssertionResponse](docs/CredentialAssertionResponse.md)
Expand Down
10 changes: 10 additions & 0 deletions Sources/Passage/generated/docs/CreateUserResponse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# CreateUserResponse

## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**user** | [**User**](User.md) | |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


4 changes: 2 additions & 2 deletions Sources/Passage/generated/docs/UsersAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ No authorization required

# **createUser**
```swift
open class func createUser(appId: String, createUserParams: CreateUserParams, completion: @escaping (_ data: UserResponse?, _ error: Error?) -> Void)
open class func createUser(appId: String, createUserParams: CreateUserParams, completion: @escaping (_ data: CreateUserResponse?, _ error: Error?) -> Void)
```

Create User
Expand Down Expand Up @@ -99,7 +99,7 @@ Name | Type | Description | Notes

### Return type

[**UserResponse**](UserResponse.md)
[**CreateUserResponse**](CreateUserResponse.md)

### Authorization

Expand Down
7 changes: 2 additions & 5 deletions Sources/Passage/interfaces/PassageApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,11 @@ public class PassageApp {
identifier: identifier,
userMetadata: userMetadata
)
let resposne = try await UsersAPI.createUser(
let response = try await UsersAPI.createUser(
appId: appId,
createUserParams: params
)
guard let user = resposne.user else {
throw PassageAppError.invalidRequest(message: "invalid request")
}
return user
return response.user
} catch {
throw PassageAppError.convert(error: error)
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Passage/interfaces/PassageCurrentUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ final public class PassageCurrentUser {
/// - Returns: `AuthResult`
/// - Throws: `CurrentUserError`
@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
@discardableResult
public func addPasskey(options: PasskeyCreationOptions? = nil) async throws -> AuthResult {
setAuthTokenHeader()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Passage/interfaces/PassageHosted.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class PassageHosted {
self.appId = appId
tokenStore = PassageTokenStore(appId: appId)
}

#if os(iOS)
/// Authentication method for Passage Hosted apps
///
Expand Down Expand Up @@ -65,4 +66,3 @@ public class PassageHosted {
}
#endif
}

2 changes: 2 additions & 0 deletions Sources/Passage/interfaces/PassagePasskey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public final class PassagePasskey {
/// - Returns: `AuthResult`
/// - Throws: `PassagePasskeyError`
@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
@discardableResult
public func register(
identifier: String,
Expand Down Expand Up @@ -63,6 +64,7 @@ public final class PassagePasskey {
/// - Returns: `AuthResult`
/// - Throws: `PassagePasskeyError`
@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
@discardableResult
public func login(identifier: String? = nil) async throws -> AuthResult {
do {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Passage/interfaces/PassageSocial.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation

/// A class for enabling user authentication via social providers like Apple, Google, and GitHub.
#if !os(tvOS)
public class PassageSocial {

private let appId: String
Expand All @@ -11,7 +10,8 @@ public class PassageSocial {
self.appId = appId
tokenStore = PassageTokenStore(appId: appId)
}


#if os(iOS) || os(macOS) || os(visionOS)
/// Authorizes user via a supported third-party social provider.
///
/// Using `PassageSocialConnection.apple` connection triggers the native Sign in with Apple
Expand Down Expand Up @@ -77,6 +77,6 @@ public class PassageSocial {
internal func getSocialAuthUrl(queryParams: String) -> URL? {
return URL(string: "\(OpenAPIClientAPI.basePath)/apps/\(appId)/social/authorize?\(queryParams)")
}
#endif

}
#endif
2 changes: 2 additions & 0 deletions Sources/Passage/services/PassageClientService.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#if os(macOS)
import Foundation
#elseif os(watchOS)
import WatchKit
#else
import UIKit
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AuthenticationServices

@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
internal typealias AssertionCredentialContinuation = CheckedContinuation<
ASAuthorizationPublicKeyCredentialAssertion,
Error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AuthenticationServices

@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
internal class PasskeyAuthenticationController:
NSObject,
ASAuthorizationControllerDelegate {
Expand Down Expand Up @@ -29,7 +30,8 @@ internal class PasskeyAuthenticationController:
.createCredentialRegistrationRequest(
challenge: registrationRequest.challenge,
name: registrationRequest.userName,
userID: registrationRequest.userId
userID: registrationRequest.userId,
requestStyle: .conditional
)
}
}
Expand Down Expand Up @@ -153,10 +155,12 @@ internal class PasskeyAuthenticationController:
}

@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
extension PasskeyAuthenticationController: ASAuthorizationControllerPresentationContextProviding {

#if os(iOS) || os(visionOS)
@available(iOS 16.0, visionOS 1.0, *)
@available(tvOS, unavailable)
@available(macOS, unavailable)
internal func requestPasskeyAssertionAutoFill (
assertionRequest: PasskeyAssertionRequest
) async throws -> ASAuthorizationPublicKeyCredentialAssertion {
Expand All @@ -180,16 +184,16 @@ extension PasskeyAuthenticationController: ASAuthorizationControllerPresentation
}
)
}
#endif


// MARK: - ASAuthorizationControllerPresentationContextProviding Methods

#if !os(watchOS)
internal func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
#if os(macOS)
return NSApp.windows.last(where: \.isKeyWindow) ?? ASPresentationAnchor()
#else
return UIApplication.shared.windows.last(where: \.isKeyWindow) ?? ASPresentationAnchor()
#endif
}
#endif

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import AuthenticationServices

@available(iOS 16.0, macOS 12.0, tvOS 16.0, visionOS 1.0, *)
@available(watchOS, unavailable)
internal typealias RegistrationCredentialContinuation = CheckedContinuation<
ASAuthorizationPublicKeyCredentialRegistration,
Error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import AuthenticationServices
#if os(iOS)
import SafariServices

#if os(iOS)
final internal class HostedAuthorizationController:
NSObject,
ASWebAuthenticationPresentationContextProviding,
SFSafariViewControllerDelegate {
final internal class HostedAuthorizationController: NSObject {

// MARK: - INSTANCE PROPERTIES

Expand Down Expand Up @@ -131,7 +128,7 @@ final internal class HostedAuthorizationController:

@MainActor
@available(iOS 17.4, macOS 14.4, *)
func logout(idToken: String) async throws {
internal func logout(idToken: String) async throws {
let url = try getLogoutUrl(idToken: idToken)
guard
let logoutUrl = URL(string: logoutUrlString),
Expand Down Expand Up @@ -267,6 +264,12 @@ final internal class HostedAuthorizationController:
return UIApplication.shared.windows.last(where: \.isKeyWindow) ?? ASPresentationAnchor()
}

}

extension HostedAuthorizationController:
ASWebAuthenticationPresentationContextProviding,
SFSafariViewControllerDelegate {

// MARK: - SFSafariViewControllerDelegate METHODS

internal func safariViewController(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public enum PassageSocialConnection: String {
case google
}

#if !os(tvOS)
#if os(iOS) || os(macOS) || os(visionOS)
final internal class PassageSocialAuthController:
NSObject,
ASWebAuthenticationPresentationContextProviding,
Expand Down

0 comments on commit bb7a94a

Please sign in to comment.