@@ -98,7 +98,7 @@ open class OAuth2: OAuth2Base {
98
98
99
99
- parameter params: Optional key/value pairs to pass during authorization and token refresh
100
100
- parameter callback: The callback to call when authorization finishes (parameters will be non-nil but may be an empty dict), fails or
101
- is canceled (error will be non-nil, e.g. `.requestCancelled` if auth was aborted)
101
+ is canceled (error will be non-nil, e.g. `.requestCancelled` if auth was aborted)
102
102
*/
103
103
public final func authorize( params: OAuth2StringDict ? = nil , callback: @escaping ( ( OAuth2JSON ? , OAuth2Error ? ) -> Void ) ) {
104
104
if isAuthorizing {
@@ -142,7 +142,7 @@ open class OAuth2: OAuth2Base {
142
142
- parameter from: The context to start authorization from, depends on platform (UIViewController or NSWindow, see `authorizeContext`)
143
143
- parameter params: Optional key/value pairs to pass during authorization
144
144
- parameter callback: The callback to call when authorization finishes (parameters will be non-nil but may be an empty dict), fails or
145
- is canceled (error will be non-nil, e.g. `.requestCancelled` if auth was aborted)
145
+ is canceled (error will be non-nil, e.g. `.requestCancelled` if auth was aborted)
146
146
*/
147
147
open func authorizeEmbedded( from context: AnyObject , params: OAuth2StringDict ? = nil , callback: @escaping ( ( _ authParameters: OAuth2JSON ? , _ error: OAuth2Error ? ) -> Void ) ) {
148
148
if isAuthorizing { // `authorize()` will check this, but we want to exit before changing `authConfig`
@@ -181,7 +181,7 @@ open class OAuth2: OAuth2Base {
181
181
182
182
- parameter params: Optional key/value pairs to pass during authorization
183
183
- parameter callback: The callback to call once the client knows whether it has an access token or not; if `success` is true an
184
- access token is present
184
+ access token is present
185
185
*/
186
186
open func tryToObtainAccessTokenIfNeeded( params: OAuth2StringDict ? = nil , callback: @escaping ( ( OAuth2JSON ? , OAuth2Error ? ) -> Void ) ) {
187
187
if hasUnexpiredAccessToken ( ) {
@@ -268,7 +268,7 @@ open class OAuth2: OAuth2Base {
268
268
Method that creates the OAuth2AuthRequest instance used to create the authorize URL
269
269
270
270
- parameter redirect: The redirect URI string to supply. If it is nil, the first value of the settings' `redirect_uris` entries is
271
- used. Must be present in the end!
271
+ used. Must be present in the end!
272
272
- parameter scope: The scope to request
273
273
- parameter params: Any additional parameters as dictionary with string keys and values that will be added to the query part
274
274
- returns: OAuth2AuthRequest to be used to call to the authorize endpoint
@@ -318,7 +318,7 @@ open class OAuth2: OAuth2Base {
318
318
Convenience method to be overridden by and used from subclasses.
319
319
320
320
- parameter redirect: The redirect URI string to supply. If it is nil, the first value of the settings' `redirect_uris` entries is
321
- used. Must be present in the end!
321
+ used. Must be present in the end!
322
322
- parameter scope: The scope to request
323
323
- parameter params: Any additional parameters as dictionary with string keys and values that will be added to the query part
324
324
- returns: NSURL to be used to start the OAuth dance
@@ -391,6 +391,9 @@ open class OAuth2: OAuth2Base {
391
391
callback ( json, nil )
392
392
}
393
393
catch let error {
394
+ // Fixes [Issue #367](https://github.com/p2/OAuth2/issues/367)
395
+ // Refresh token needs to be cleared out upon error, otherwise re-authorizing will not ocurr because the library thinks it has a valid refresh token and tries to fetch a new access token with an expired refresh token.
396
+ self . clientConfig. refreshToken = nil
394
397
self . logger? . debug ( " OAuth2 " , msg: " Error refreshing access token: \( error) " )
395
398
callback ( nil , error. asOAuth2Error)
396
399
}
@@ -412,7 +415,7 @@ open class OAuth2: OAuth2Base {
412
415
If both are nil, instantiates a blank `OAuth2DynReg` instead, then attempts client registration.
413
416
414
417
- parameter callback: The callback to call on the main thread; if both json and error is nil no registration was attempted; error is nil
415
- on success
418
+ on success
416
419
*/
417
420
public func registerClientIfNeeded( callback: @escaping ( ( OAuth2JSON ? , OAuth2Error ? ) -> Void ) ) {
418
421
if nil != clientId || !type( of: self ) . clientIdMandatory {
0 commit comments