Skip to content

Commit

Permalink
Renamed clearAndRevokeToken to revoke, updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Hobbs committed Oct 7, 2019
1 parent d4a90e0 commit 9d65c7f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Auth0/CredentialsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public struct CredentialsManager {
/// the credentials are not cleared and an error is raised through the callback.
///
/// - Parameter callback: callback with an error if the refresh token could not be revoked
public func clearAndRevokeToken(_ callback: @escaping (CredentialsManagerError?) -> Void) {
public func revoke(_ callback: @escaping (CredentialsManagerError?) -> Void) {
guard
let data = self.storage.data(forKey: self.storeKey),
let credentials = NSKeyedUnarchiver.unarchiveObject(with: data) as? Credentials,
Expand Down
8 changes: 4 additions & 4 deletions Auth0Tests/CredentialsManagerSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CredentialsManagerSpec: QuickSpec {

it("should clear credentials and revoke the refresh token") {
waitUntil(timeout: 2) { done in
credentialsManager.clearAndRevokeToken {
credentialsManager.revoke {
expect($0).to(beNil())
expect(credentialsManager.hasValid()).to(beFalse())
done()
Expand All @@ -99,7 +99,7 @@ class CredentialsManagerSpec: QuickSpec {
_ = credentialsManager.clear()

waitUntil(timeout: 2) { done in
credentialsManager.clearAndRevokeToken {
credentialsManager.revoke {
expect($0).to(beNil())
expect(credentialsManager.hasValid()).to(beFalse())
done()
Expand All @@ -117,7 +117,7 @@ class CredentialsManagerSpec: QuickSpec {
_ = credentialsManager.store(credentials: credentials)

waitUntil(timeout: 2) { done in
credentialsManager.clearAndRevokeToken {
credentialsManager.revoke {
expect($0).to(beNil())
expect(credentialsManager.hasValid()).to(beFalse())
done()
Expand All @@ -131,7 +131,7 @@ class CredentialsManagerSpec: QuickSpec {
}

waitUntil(timeout: 2) { done in
credentialsManager.clearAndRevokeToken {
credentialsManager.revoke {
expect($0).to(matchError(
CredentialsManagerError.revokeFailed(AuthenticationError(string: "Revoke failed", statusCode: 400))
))
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,20 @@ credentialsManager.credentials { error, credentials in
}
```

#### Clearing credentials
#### Clearing credentials and revoking refresh tokens

Credentials can be cleared by using the `clearAndRevokeToken` function. This function will attempt to revoke any associated refresh token that has been stored, before clearing the credentials from memory:
Credentials can be cleared by using the `clear` function, which clears credentials from memory:

```swift
credentialsManager.clearAndRevokeToken { error in
let didClear = credentialsManager.clear()
```

In addition, credentials can be cleared and the refresh token revoked using a single call to `revoke`. This function will attempt to revoke any associated refresh token that has been stored, before clearing the credentials from memory. If revoking the token results in an error, then the credentials are not cleared.

This method is asynchronous, so a callback should be specified to handle the result:

```swift
credentialsManager.revoke { error in
guard error == nil else {
return print("Failed to clear credentials")
}
Expand Down

0 comments on commit 9d65c7f

Please sign in to comment.