Skip to content

Commit

Permalink
Merge pull request #158 from everlof/develop
Browse files Browse the repository at this point in the history
Add workaround for issue in Safari
  • Loading branch information
p2 authored Nov 19, 2016
2 parents 5d5e3e1 + 8f00d6f commit 0f9f8c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Sources/Base/OAuth2ClientConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,19 @@ open class OAuth2ClientConfig {

/// Custom request parameters to be added during authorization.
open var authParameters: OAuth2StringDict?


/// There's an issue with authenticating through 'system browser', where safari says:
/// "Safari cannot open the page because the address is invalid." if you first selects 'Cancel'
/// when asked to switch back to "your" app, and then you try authenticating again.
/// To get rid of it you must restart Safari.
///
/// Read more about it here:
/// http://stackoverflow.com/questions/27739442/ios-safari-does-not-recognize-url-schemes-after-user-cancels
/// https://community.fitbit.com/t5/Web-API/oAuth2-authentication-page-gives-me-a-quot-Cannot-Open-Page-quot-error/td-p/1150391
///
/// Toggling `safariCancelWorkaround` to true will send an extra get-paramter to make the url unique,
/// thus it will ask again for the new url.
open var safariCancelWorkaround = false

/**
Initializer to initialize properties from a settings dictionary.
Expand Down
3 changes: 3 additions & 0 deletions Sources/Flows/OAuth2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@ open class OAuth2: OAuth2Base {
req.params["redirect_uri"] = redirect
req.params["client_id"] = clientId
req.params["state"] = context.state
if clientConfig.safariCancelWorkaround {
req.params["swa"] = "\(Date.timeIntervalSinceReferenceDate)" // Safari issue workaround
}
if let scope = scope ?? clientConfig.scope {
req.params["scope"] = scope
}
Expand Down

0 comments on commit 0f9f8c4

Please sign in to comment.