Skip to content

Commit

Permalink
add call to oauth.disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
sagishm committed Apr 21, 2024
1 parent 637210d commit ea7f1d6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ class SocialLoginProvider: Provider {
func getProviderSessions(token: String, expiration: String?, code: String?, firstName: String?, lastName: String?) -> String {
switch providerType {
case .facebook:
return "{\"\(providerType.rawValue)\": {\"authToken\": \"\(token)\", tokenExpiration: \"\(expiration ?? "")\"}}"
if let code = code {
return "{\"\(providerType.rawValue)\": {\"authToken\": \"\(token)\", tokenExpiration: \"\(expiration ?? "")\", idToken: \"\(code)\"}}"
} else {
return "{\"\(providerType.rawValue)\": {\"authToken\": \"\(token)\", tokenExpiration: \"\(expiration ?? "")\"}}"
}
case .line:
return "{\"\(providerType.rawValue)\":{\"authToken\": \"\(token)\"}}"
case .google:
Expand Down
9 changes: 9 additions & 0 deletions GigyaSwift/Global/WebAuthn/OauthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ class OauthService {
}
}

func disconnect(regToken: String, idToken: String, ignoreApiQueue: Bool = true, completion: @escaping (GigyaApiResult<GigyaDictionary>) -> Void) {
var model = ApiRequestModel(method: GigyaDefinitions.Oauth.disconnect, params: ["ignoreApiQueue": ignoreApiQueue, "regToken": regToken])
model.headers = ["Authorization": "Bearer \(idToken)"]
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
Expand Down
17 changes: 15 additions & 2 deletions GigyaSwift/Global/WebAuthn/WebAuthnService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,21 @@ public class WebAuthnService<T: GigyaAccountProtocol> {
private func revoke(key: String) async -> GigyaApiResult<GigyaDictionary> {
return await withCheckedContinuation({
continuation in
businessApiService.send(dataType: GigyaDictionary.self, api: GigyaDefinitions.WenAuthn.removeCredential, params: ["credentialId": key]) { result in
continuation.resume(returning: result)
businessApiService.send(dataType: GigyaDictionary.self, api: GigyaDefinitions.WenAuthn.removeCredential, params: ["credentialId": key]) { [weak self] result in
switch result {
case .success(let data):
guard let idToken = data["idToken"]?.value as? String else {
continuation.resume(returning: result)
return
}

self?.oauthService.disconnect(regToken: key, idToken: idToken) { _ in
continuation.resume(returning: result)
}
case .failure(_):
continuation.resume(returning: result)
}

}
})
}
Expand Down
1 change: 1 addition & 0 deletions GigyaSwift/Models/Config/GigyaDefinitions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public struct GigyaDefinitions {

public struct Oauth {
static let connect = "oauth.connect"
static let disconnect = "oauth.disconnect"
static let authorize = "oauth.authorize"
static let token = "oauth.token"
}
Expand Down

0 comments on commit ea7f1d6

Please sign in to comment.