Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support customizable callback url-scheme. #296

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions Sources/SwifterAuth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ public extension Swifter {
}

let urlScheme = "swifter-\(client.consumerKey)"
authorizeSSO(withCallback: urlScheme, success: success, failure: failure)
}

func authorizeSSO(withCallback urlScheme: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating the method signature with a customizable callback URL, this should use an optional callback.

func authorizeSSO(
    withCallbackURLScheme urlScheme: String? = nil, 
    success: SSOTokenSuccessHandler, 
    failure: FailureHandler? = nil
) {
    guard let client = client as? SwifterAppProtocol else { 
        // handle error
        return
    } 
    let urlScheme = urlScheme ?? "swifter-\(client.consumerKey)"
    // ...
}

success: SSOTokenSuccessHandler?,
failure: FailureHandler? = nil) {
guard let client = client as? SwifterAppProtocol else {
let error = SwifterError(message: "SSO not supported AppOnly client",
kind: .invalidClient)
failure?(error)
return
}

let nc = NotificationCenter.default
self.swifterCallbackToken = nc.addObserver(forName: .swifterSSOCallback, object: nil, queue: .main) { notification in
Expand Down