diff --git a/README.md b/README.md index e5b4473..9afc787 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Tests/OAuthenticatorTests/AuthenticatorTests.swift b/Tests/OAuthenticatorTests/AuthenticatorTests.swift index 89e0a5e..e2daa27 100644 --- a/Tests/OAuthenticatorTests/AuthenticatorTests.swift +++ b/Tests/OAuthenticatorTests/AuthenticatorTests.swift @@ -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")!))