Skip to content

Commit

Permalink
Update readme to refer to new AuthenticationResult capability
Browse files Browse the repository at this point in the history
Update test case for AuthenticationResult
  • Loading branch information
martindufort committed Sep 27, 2023
1 parent bdc0426 commit 2ddc0ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,31 @@ let myRequest = URLRequest(...)
let (data, response) = try await authenticator.response(for: myRequest)
```

If you want to receive the result of the authentication process without issuing a URLRequest first, you can specify
an optional `Authenticator.AuthenticationResult` callback function within the `Authenticator.Configuration` initializer.

This allows you to support special cases where you need to capture the `Login` object before executing your first
authenticated URLRequest and manage that separately.

``` swift
let authenticationResultCallback: Authenticator.AuthenticationResult = { login, error in
...
authenticatedLogin = login
}

// Configure Authenticator with result callback
let config = Authenticator.Configuration(appCredentials: appCreds,
tokenHandling: tokenHandling,
mode: .manualOnly,
userAuthenticator: userAuthenticator,
authenticationResult: authenticationResultCallback)
let auth = Authenticator(config: config, urlLoader: mockLoader)
try await auth.authenticate()
if let authenticatedLogin = authenticatedLogin {
// Process special case
...
}
```

### GitHub

Expand Down
3 changes: 2 additions & 1 deletion Tests/OAuthenticatorTests/AuthenticatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,9 @@ final class AuthenticatorTests: XCTestCase {
// Explicitly authenticate and grab Login information after
try await auth.authenticate()

// Ensure our authenticatedLogin objet is available
// Ensure our authenticatedLogin objet is available and contains the proper Token
XCTAssertNotNil(authenticatedLogin)
XCTAssertEqual(authenticatedLogin?.accessToken.value, "TOKEN")

let (_, _) = try await auth.response(for: URLRequest(url: URL(string: "https://example.com")!))

Expand Down

0 comments on commit 2ddc0ea

Please sign in to comment.