Skip to content

Commit 1796ddd

Browse files
authored
add uri to callback params (#30)
- return full uri in addition to auth code so that the user can access the additonallbackparams easily Demo: https://github.com/user-attachments/assets/fec72c03-dabb-42ab-9339-fff6e947acf8
1 parent 85bb4fb commit 1796ddd

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Sources/Siwf/Siwf.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class Siwf: ObservableObject {
4242
* @param redirectUrl - The expected redirect URL registered by the app.
4343
* @param processAuthorization - A closure that handles the extracted authorization code.
4444
*/
45-
public static func handleRedirectUrl(incomingUrl: URL, redirectUrl: URL, processAuthorization: (_ authorizationCode: String) -> Void) -> Void {
45+
public static func handleRedirectUrl(incomingUrl: URL, redirectUrl: URL, processAuthorization: (_ authorizationCode: String, _ authorizationUri: URL) -> Void) -> Void {
4646
// No active safari view? Cannot be us
4747
if !shared.safariViewActive {
4848
return
@@ -57,11 +57,13 @@ public class Siwf: ObservableObject {
5757
return
5858
}
5959

60+
let authorizationUri: URL = incomingUrl.url!
61+
6062
debugPrint("Captured authorizationCode: \(authorizationCode)")
6163
// Trigger the closing of any button's SafariView
6264
shared.safariViewActive = false
6365
// TODO: Do we want to swap the authorizationCode for the full payload?
6466
// Trigger the callback
65-
processAuthorization(authorizationCode)
67+
processAuthorization(authorizationCode, authorizationUri)
6668
}
6769
}

Sources/Siwf/SiwfButton.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct SiwfButton: View {
4444
}
4545
.padding(.vertical, 6)
4646
.padding(.leading, -6)
47-
.frame(width: 254)
47+
.frame(width: 276)
4848
.background(buttonStyle.backgroundColor)
4949
.foregroundColor(buttonStyle.textColor)
5050
.overlay(

example-app/SiwfApp/SiwfApp.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Siwf
1111
struct SiwfApp: App {
1212
@State private var showAlert = false
1313
@State private var authorizationCode: String = ""
14+
@State private var authorizationUri: String = ""
1415

1516
var body: some Scene {
1617
WindowGroup {
@@ -27,9 +28,11 @@ struct SiwfApp: App {
2728
Siwf.handleRedirectUrl(
2829
incomingUrl: url,
2930
redirectUrl: redirectUrl,
30-
processAuthorization: { code in
31-
print("✅ Successfully extracted authorization code: \(code)")
32-
authorizationCode = code
31+
processAuthorization: { incomingAuthCode, incomingAuthUri in
32+
print("✅ Successfully extracted authorization code: \(incomingAuthCode)")
33+
print("✅ Successfully received the authorization uri: \(incomingAuthUri)")
34+
authorizationCode = incomingAuthCode
35+
authorizationUri = incomingAuthUri.absoluteString
3336
showAlert = true
3437
// Process the authorizationCode by sending it it your backend servers
3538
// See https://projectlibertylabs.github.io/siwf/v2/docs/Actions/Response.html
@@ -39,7 +42,11 @@ struct SiwfApp: App {
3942
.alert("Success!", isPresented: $showAlert) {
4043
Button("OK", role: .cancel) { }
4144
} message: {
42-
Text("Received Authorization Code: \(authorizationCode)")
45+
Text("""
46+
Received Authorization Code: \(authorizationCode)
47+
48+
Received Authorization Uri: \(authorizationUri)
49+
""")
4350
}
4451
}
4552
}

0 commit comments

Comments
 (0)