Skip to content

Commit 1b25f57

Browse files
committed
Remove deprecated callbacks
1 parent 85efd6d commit 1b25f57

File tree

6 files changed

+4
-144
lines changed

6 files changed

+4
-144
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ You can also refer to commit logs to get details on what was implemented, fixed
1010
- Move `secretInBody` and `customParameters` from `authConfig` to `clientConfig`, where they belong
1111
- Allow to override default UTF-8 encoding of the _Basic_ authorization header
1212
- Improvements to embedded authorization
13+
- Remove `onAuthorize` and `onFailure` callbacks, which have been deprecated with 3.0 (now handled in the callback to `authorize()`)
1314

1415

1516
### 3.0.1

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ You only need to inspect the _authParameters_ dictionary if you wish to extract
169169

170170
For advanced use outlined below, there is the `afterAuthorizeOrFail` block that you can use on your OAuth2 instance.
171171
The `internalAfterAuthorizeOrFail` closure is, as its name suggests, provided for internal purposes – it is exposed for subclassing and compilation reasons and you should not mess with it.
172-
Additionally, as of version 3.0, there are deprecated callback properties `onAuthorize` and `onFailure` that you should no longer use.
172+
As of version 3.0.2, you can no longer use the `onAuthorize` and `onFailure` callback properties, they have been removed entirely.
173173

174174
### 6. Make Requests
175175

Sources/Base/OAuth2Base.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ open class OAuth2Base: OAuth2Securable {
129129
return nil != didAuthorizeOrFail
130130
}
131131

132-
/// Closure called on successful authorization on the main thread.
133-
@available(*, deprecated: 3.0, message: "Use the `authorize(params:callback:)` method and variants")
134-
public final var onAuthorize: ((_ parameters: OAuth2JSON) -> Void)?
135-
136-
/// When authorization fails (if error is not nil) or is cancelled, this block is executed on the main thread.
137-
@available(*, deprecated: 3.0, message: "Use the `authorize(params:callback:)` method and variants")
138-
public final var onFailure: ((OAuth2Error?) -> Void)?
139-
140132
/**
141133
Closure called after the regular authorization callback, on the main thread. You can use this callback when you're performing
142134
authorization manually and/or for cleanup operations.
@@ -267,7 +259,6 @@ open class OAuth2Base: OAuth2Securable {
267259
storeTokensToKeychain()
268260
}
269261
callOnMainThread() {
270-
self.onAuthorize?(parameters)
271262
self.didAuthorizeOrFail?(parameters, nil)
272263
self.didAuthorizeOrFail = nil
273264
self.internalAfterAuthorizeOrFail?(false, nil)
@@ -292,7 +283,6 @@ open class OAuth2Base: OAuth2Securable {
292283
finalError = OAuth2Error.requestCancelled
293284
}
294285
callOnMainThread() {
295-
self.onFailure?(finalError)
296286
self.didAuthorizeOrFail?(nil, finalError)
297287
self.didAuthorizeOrFail = nil
298288
self.internalAfterAuthorizeOrFail?(true, finalError)

Sources/Flows/OAuth2.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ open class OAuth2: OAuth2Base {
8686
This method will first check if the client already has an unexpired access token (possibly from the keychain), if not and it's able to
8787
use a refresh token it will try to use the refresh token. If this fails it will check whether the client has a client_id and show the
8888
authorize screen if you have `authConfig` set up sufficiently. If `authConfig` is not set up sufficiently this method will end up
89-
calling the `onFailure` callback. If client_id is not set but a "registration_uri" has been provided, a dynamic client registration will
90-
be attempted and if it success, an access token will be requested.
89+
calling the callback with a failure. If client_id is not set but a "registration_uri" has been provided, a dynamic client registration
90+
will be attempted and if it success, an access token will be requested.
9191

9292
- parameter params: Optional key/value pairs to pass during authorization and token refresh
9393
- parameter callback: The callback to call when authorization finishes (parameters will be non-nil but may be an empty dict), fails or

Tests/BaseTests/OAuth2Tests.swift

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -89,35 +89,6 @@ class OAuth2Tests: XCTestCase {
8989
XCTAssertNil(params["state"], "Expecting no `state` in query")
9090
}
9191

92-
func testDeprecatedAuthorizeCall() {
93-
let oa = genericOAuth2()
94-
oa.verbose = false
95-
XCTAssertFalse(oa.authConfig.authorizeEmbedded)
96-
oa.onAuthorize = { params in
97-
XCTAssertTrue(false, "Should not call success callback")
98-
}
99-
oa.onFailure = { error in
100-
XCTAssertNotNil(error)
101-
XCTAssertEqual(error, OAuth2Error.noRedirectURL)
102-
}
103-
oa.authorize()
104-
XCTAssertFalse(oa.authConfig.authorizeEmbedded)
105-
106-
// embedded
107-
oa.redirect = "myapp://oauth"
108-
oa.onFailure = { error in
109-
XCTAssertNotNil(error)
110-
XCTAssertEqual(error, OAuth2Error.invalidAuthorizationContext)
111-
}
112-
oa.afterAuthorizeOrFail = { params, error in
113-
XCTAssertNil(params)
114-
XCTAssertNotNil(error)
115-
XCTAssertEqual(error, OAuth2Error.invalidAuthorizationContext)
116-
}
117-
oa.authorizeEmbedded(from: NSString())
118-
XCTAssertTrue(oa.authConfig.authorizeEmbedded)
119-
}
120-
12192
func testAuthorizeCall() {
12293
let oa = genericOAuth2()
12394
oa.verbose = false

Tests/FlowTests/OAuth2ImplicitGrantTests.swift

Lines changed: 0 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -45,108 +45,6 @@ class OAuth2ImplicitGrantTests: XCTestCase
4545
XCTAssertEqual(oauth.authURL, URL(string: "https://auth.ful.io")!, "Must init `authorize_uri`")
4646
}
4747

48-
func testDeprecatedReturnURLHandling() {
49-
let oauth = OAuth2ImplicitGrant(settings: [
50-
"client_id": "abc",
51-
"authorize_uri": "https://auth.ful.io",
52-
"keychain": false,
53-
])
54-
55-
// Empty redirect URL
56-
oauth.onFailure = { error in
57-
XCTAssertNotNil(error, "Error message expected")
58-
XCTAssertEqual(error, OAuth2Error.invalidRedirectURL("file:///"))
59-
}
60-
oauth.afterAuthorizeOrFail = { authParameters, error in
61-
XCTAssertNil(authParameters)
62-
XCTAssertNotNil(error, "Error message expected")
63-
}
64-
oauth.context._state = "ONSTUH"
65-
oauth.handleRedirectURL(URL(string: "file:///")!)
66-
XCTAssertNil(oauth.accessToken, "Must not have an access token")
67-
68-
// No params in redirect URL
69-
oauth.onFailure = { error in
70-
XCTAssertNotNil(error, "Error message expected")
71-
XCTAssertEqual(error, OAuth2Error.invalidRedirectURL("https://auth.ful.io"))
72-
}
73-
oauth.handleRedirectURL(URL(string: "https://auth.ful.io")!)
74-
XCTAssertNil(oauth.accessToken, "Must not have an access token")
75-
76-
// standard error
77-
oauth.context._state = "ONSTUH" // because it has been reset
78-
oauth.onFailure = { error in
79-
XCTAssertNotNil(error, "Error message expected")
80-
XCTAssertEqual(error, OAuth2Error.accessDenied)
81-
XCTAssertEqual(error?.description, "The resource owner or authorization server denied the request.")
82-
}
83-
oauth.handleRedirectURL(URL(string: "https://auth.ful.io#error=access_denied")!)
84-
XCTAssertNil(oauth.accessToken, "Must not have an access token")
85-
86-
// explicit error
87-
oauth.context._state = "ONSTUH" // because it has been reset
88-
oauth.onFailure = { error in
89-
XCTAssertNotNil(error, "Error message expected")
90-
XCTAssertNotEqual(error, OAuth2Error.generic("Not good"))
91-
XCTAssertEqual(error, OAuth2Error.responseError("Not good"))
92-
XCTAssertEqual(error?.description, "Not good")
93-
}
94-
oauth.handleRedirectURL(URL(string: "https://auth.ful.io#error_description=Not+good")!)
95-
XCTAssertNil(oauth.accessToken, "Must not have an access token")
96-
97-
// no token type
98-
oauth.context._state = "ONSTUH" // because it has been reset
99-
oauth.onFailure = { error in
100-
XCTAssertNotNil(error, "Error message expected")
101-
XCTAssertEqual(error, OAuth2Error.noTokenType)
102-
}
103-
oauth.handleRedirectURL(URL(string: "https://auth.ful.io#access_token=abc&state=\(oauth.context.state)")!)
104-
XCTAssertNil(oauth.accessToken, "Must not have an access token")
105-
106-
// unsupported token type
107-
oauth.context._state = "ONSTUH" // because it has been reset
108-
oauth.onFailure = { error in
109-
XCTAssertNotNil(error, "Error message expected")
110-
XCTAssertEqual(error, OAuth2Error.unsupportedTokenType("Only “bearer” token is supported, but received “helicopter”"))
111-
}
112-
oauth.handleRedirectURL(URL(string: "https://auth.ful.io#token_type=helicopter&access_token=abc&state=\(oauth.context.state)")!)
113-
XCTAssertNil(oauth.accessToken, "Must not have an access token")
114-
115-
// Invalid state
116-
oauth.context._state = "ONSTUH" // because it has been reset
117-
oauth.onFailure = { error in
118-
XCTAssertNotNil(error, "Error message expected")
119-
XCTAssertEqual(error, OAuth2Error.invalidState)
120-
}
121-
oauth.handleRedirectURL(URL(string: "https://auth.ful.io#token_type=bearer&access_token=abc&state=ONSTOH")!)
122-
XCTAssertNil(oauth.accessToken, "Must not have an access token")
123-
124-
// success 1
125-
oauth.onFailure = { error in
126-
XCTAssertTrue(false, "Should not call this")
127-
}
128-
oauth.afterAuthorizeOrFail = { authParameters, error in
129-
XCTAssertNotNil(authParameters, "Expecting non-nil auth dict")
130-
XCTAssertTrue((authParameters?.count ?? 0) > 2, "Expecting non-empty auth dict")
131-
XCTAssertNil(error, "No error message expected")
132-
}
133-
oauth.handleRedirectURL(URL(string: "https://auth.ful.io#token_type=bearer&access_token=abc&state=\(oauth.context.state)&expires_in=3599")!)
134-
XCTAssertNotNil(oauth.accessToken, "Must have an access token")
135-
XCTAssertEqual(oauth.accessToken!, "abc")
136-
XCTAssertNotNil(oauth.accessTokenExpiry)
137-
XCTAssertTrue(oauth.hasUnexpiredAccessToken())
138-
139-
// success 2
140-
oauth.onFailure = { error in
141-
XCTAssertTrue(false, "Should not call this")
142-
}
143-
oauth.handleRedirectURL(URL(string: "https://auth.ful.io#token_type=bearer&access_token=abc&state=\(oauth.context.state)")!)
144-
XCTAssertNotNil(oauth.accessToken, "Must have an access token")
145-
XCTAssertEqual(oauth.accessToken!, "abc")
146-
XCTAssertNil(oauth.accessTokenExpiry)
147-
XCTAssertTrue(oauth.hasUnexpiredAccessToken())
148-
}
149-
15048
func testReturnURLHandling() {
15149
let oauth = OAuth2ImplicitGrant(settings: [
15250
"client_id": "abc",

0 commit comments

Comments
 (0)