From 2ddc0ea464c177c7720a478d434bd1a6cd6ec408 Mon Sep 17 00:00:00 2001 From: Martin Dufort Date: Wed, 27 Sep 2023 12:14:37 -0700 Subject: [PATCH] Update readme to refer to new AuthenticationResult capability Update test case for AuthenticationResult --- README.md | 25 +++++++++++++++++++ .../AuthenticatorTests.swift | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) 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")!))