-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
967 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// OauthService.swift | ||
// Gigya | ||
// | ||
// Created by Sagi Shmuel on 05/07/2022. | ||
// Copyright © 2022 Gigya. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class OauthService { | ||
let businessApiService: BusinessApiServiceProtocol | ||
|
||
init(businessApiService: BusinessApiServiceProtocol) { | ||
self.businessApiService = businessApiService | ||
} | ||
|
||
func connect(token: String, completion: @escaping (GigyaApiResult<GigyaDictionary>) -> Void) { | ||
var model = ApiRequestModel(method: GigyaDefinitions.Oauth.connect) | ||
model.headers = ["Authorization": "Bearer \(token)"] | ||
businessApiService.apiService.send(model: model, responseType: GigyaDictionary.self) { result in | ||
completion(result) | ||
} | ||
} | ||
|
||
@available(iOS 13.0.0, *) | ||
func authorize<T: Codable>(token: String) async -> GigyaLoginResult<T> { | ||
return await withCheckedContinuation { [weak self] continuation in | ||
guard let self = self else { return } | ||
|
||
var model = ApiRequestModel(method: GigyaDefinitions.Oauth.authorize, params: ["response_type": "code"]) | ||
model.headers = ["Authorization": "Bearer \(token)"] | ||
|
||
self.businessApiService.apiService.send(model: model, responseType: GigyaDictionary.self) { result in | ||
switch result { | ||
case .success(data: let data): | ||
self.token(continuation: continuation, code: data["code"]?.value as! String) | ||
case .failure(let error): | ||
continuation.resume(returning: GigyaLoginResult.failure(.init(error: error))) | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
@available(iOS 13.0.0, *) | ||
private func token<T: Codable>(continuation: CheckedContinuation<GigyaLoginResult<T>, Never>, code: String) { | ||
self.businessApiService.send(dataType: T.self, api: GigyaDefinitions.Oauth.token, params: ["grant_type": "authorization_code", "code": code]) { [weak self] res in | ||
guard let self = self else { return } | ||
|
||
switch res { | ||
case .success(data: _): | ||
|
||
self.businessApiService.getAccount(params: [:], clearAccount: true, dataType: T.self) { result in | ||
switch result { | ||
case .success(data: let data): | ||
continuation.resume(returning: .success(data: data)) | ||
case .failure(let error): | ||
continuation.resume(returning: .failure(LoginApiError.init(error: error))) | ||
} | ||
} | ||
case .failure(let error): | ||
continuation.resume(returning: .failure(LoginApiError.init(error: error))) | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// | ||
// WebAuthnAttestationUtils.swift | ||
// Gigya | ||
// | ||
// Created by Sagi Shmuel on 24/07/2022. | ||
// Copyright © 2022 Gigya. All rights reserved. | ||
// | ||
|
||
import AuthenticationServices | ||
|
||
struct WebAuthnAttestationUtils { | ||
@available(iOS 16.0, *) | ||
func makeRegisterData(object: ASAuthorizationPlatformPublicKeyCredentialRegistration) -> [String: Any] { | ||
let response: [String: String] = [ | ||
"attestationObject": object.rawAttestationObject!.toBase64Url(), | ||
"clientDataJSON": object.rawClientDataJSON.toBase64Url() | ||
] | ||
|
||
let attestation: [String: Any] = [ | ||
"id": object.credentialID.toBase64Url(), | ||
"rawId": object.credentialID.toBase64Url(), | ||
"type": "public-key", | ||
"response": response | ||
] | ||
|
||
return attestation | ||
} | ||
|
||
@available(iOS 16.0, *) | ||
func makeRegisterData(object: ASAuthorizationSecurityKeyPublicKeyCredentialRegistration) -> [String: Any] { | ||
let response: [String: String] = [ | ||
"attestationObject": object.rawAttestationObject!.toBase64Url(), | ||
"clientDataJSON": object.rawClientDataJSON.toBase64Url() | ||
] | ||
|
||
let attestation: [String: Any] = [ | ||
"id": object.credentialID.toBase64Url(), | ||
"rawId": object.credentialID.toBase64Url(), | ||
"type": "public-key", | ||
"response": response | ||
] | ||
|
||
return attestation | ||
} | ||
|
||
|
||
@available(iOS 16.0, *) | ||
func makeLoginData(object: ASAuthorizationPlatformPublicKeyCredentialAssertion) -> [String: Any] { | ||
let response: [String: Any?] = [ | ||
"authenticatorData": object.rawAuthenticatorData.toBase64Url(), | ||
"clientDataJSON": object.rawClientDataJSON.toBase64Url(), | ||
"signature": object.signature.toBase64Url(), | ||
"userHandle": object.userID.toBase64Url() | ||
] | ||
|
||
let attestation: [String: Any] = [ | ||
"id": object.credentialID.toBase64Url(), | ||
"rawId": object.credentialID.toBase64Url(), | ||
"type": "public-key", | ||
"response": response | ||
] | ||
|
||
return attestation | ||
} | ||
|
||
@available(iOS 16.0, *) | ||
func makeSecurityLoginData(object: ASAuthorizationSecurityKeyPublicKeyCredentialAssertion) -> [String: Any] { | ||
let response: [String: Any] = [ | ||
"authenticatorData": object.rawAuthenticatorData.toBase64Url(), | ||
"clientDataJSON": object.rawClientDataJSON.toBase64Url(), | ||
"signature": object.signature.toBase64Url(), | ||
"userHandle": NSNull() | ||
] | ||
|
||
let attestation: [String: Any] = [ | ||
"id": object.credentialID.toBase64Url(), | ||
"rawId": object.credentialID.toBase64Url(), | ||
"type": "public-key", | ||
"response": response | ||
] | ||
|
||
return attestation | ||
} | ||
} |
Oops, something went wrong.