Skip to content

Commit

Permalink
FR-13828 - Add support for direct login action by ASWebAuthentication…
Browse files Browse the repository at this point in the history
…Session
  • Loading branch information
frontegg-david committed Mar 10, 2024
1 parent 77ae8e0 commit 3caa48f
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions Sources/FronteggSwift/FronteggAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,42 @@ public class FronteggAuth: ObservableObject {
self.webAuthentication.start(authorizeUrl, completionHandler: oauthCallback)
}

public func directLoginAction(window: UIWindow?, type: String, data: String, ephemeralSesion: Bool? = true, _completion: FronteggAuth.CompletionHandler? = nil) {

self.webAuthentication.webAuthSession?.cancel()
self.webAuthentication = WebAuthentication()
self.webAuthentication.window = window ?? getRootVC()?.view.window;
self.webAuthentication.ephemeralSesion = ephemeralSesion ?? true

let completion = _completion ?? { res in

}

let directLogin = [
"type": type,
"data": data,
"additionalQueryParams": [
"prompt": "consent"
]
] as [String : Any]

var generatedUrl: (URL, String)
if let jsonData = try? JSONSerialization.data(withJSONObject: directLogin, options: []) {
let jsonString = jsonData.base64EncodedString()
generatedUrl = AuthorizeUrlGenerator.shared.generate(loginAction: jsonString)
} else {
generatedUrl = AuthorizeUrlGenerator.shared.generate()
}

let oauthCallback = createOauthCallbackHandler(completion)
let (authorizeUrl, codeVerifier) = generatedUrl
CredentialManager.saveCodeVerifier(codeVerifier)
self.webAuthentication.start(authorizeUrl, completionHandler: oauthCallback)



}

internal func getRootVC() -> UIViewController? {


Expand Down

0 comments on commit 3caa48f

Please sign in to comment.