Skip to content

Commit d9ee266

Browse files
authored
Step-up flow fixed (#20)
* Bug fixed in Step-up flow fixed. Missing scope being passed causing the flow to trigger recursively * Failing test case fixed * Added documentation for scope related changes
1 parent 4e17116 commit d9ee266

4 files changed

Lines changed: 15 additions & 11 deletions

File tree

Auth0UniversalComponents/Core/Utils/ErrorHandler.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ struct ErrorHandler {
104104
handler.showLoader = false
105105
dependencies.tokenProvider.store(
106106
apiCredentials: APICredentials(from: credentials),
107-
for: dependencies.audience
107+
for: dependencies.audience,
108+
andScope: scope
108109
)
109110
retryCallback()
110111
} catch {
@@ -141,7 +142,8 @@ struct ErrorHandler {
141142
.start()
142143
dependencies.tokenProvider.store(
143144
apiCredentials: APICredentials(from: credentials),
144-
for: dependencies.audience
145+
for: dependencies.audience,
146+
andScope: scope
145147
)
146148
retryCallback()
147149
} catch {

Auth0UniversalComponents/CredentialsManager+TokenProviderExtension.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ extension CredentialsManager: TokenProvider {
2222
_ = store(credentials: credentials)
2323
}
2424

25-
/// Stores API credentials for a specific audience in the credentials manager.
25+
/// Stores API credentials for a specific audience and scope in the credentials manager.
2626
///
2727
/// - Parameters:
2828
/// - apiCredentials: The API credentials to store
2929
/// - audience: The API audience (e.g., "https://api.example.com")
30-
public func store(apiCredentials: APICredentials, for audience: String) {
31-
_ = store(apiCredentials: apiCredentials, forAudience: audience)
30+
/// - scope: The scopes associated with the credentials (space-separated)
31+
public func store(apiCredentials: APICredentials, for audience: String, andScope scope: String) {
32+
_ = store(apiCredentials: apiCredentials, forAudience: audience, forScope: scope)
3233
}
3334

3435
/// Fetches API credentials for a specific audience and scope from the credentials manager.

Auth0UniversalComponents/TokenProvider.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ import Combine
2424
/// try? credentialsManager.store(credentials: credentials)
2525
/// }
2626
///
27-
/// func store(apiCredentials: APICredentials, for audience: String) {
28-
/// apiCredentialsCache[audience] = apiCredentials
27+
/// func store(apiCredentials: APICredentials, for audience: String, andScope scope: String) {
28+
/// apiCredentialsCache["\(audience)_\(scope)"] = apiCredentials
2929
/// }
3030
///
3131
/// func fetchAPICredentials(audience: String, scope: String) async throws -> APICredentials {
32-
/// if let cached = apiCredentialsCache[audience] {
32+
/// if let cached = apiCredentialsCache["\(audience)_\(scope)"] {
3333
/// return cached
3434
/// }
3535
/// // Fetch new API credentials
3636
/// let credentials = try await Auth0.authentication()
3737
/// .credentials(forAudience: audience, scope: scope)
38-
/// store(apiCredentials: credentials, for: audience)
38+
/// store(apiCredentials: credentials, for: audience, andScope: scope)
3939
/// return credentials
4040
/// }
4141
/// }
@@ -59,7 +59,8 @@ public protocol TokenProvider: Sendable {
5959
/// - Parameters:
6060
/// - apiCredentials: The API credentials to store
6161
/// - audience: The API audience (e.g., "https://api.example.com")
62-
func store(apiCredentials: APICredentials, for audience: String)
62+
/// - scope: The scopes associated with the credentials (space-separated)
63+
func store(apiCredentials: APICredentials, for audience: String, andScope scope: String)
6364

6465
/// Fetches API credentials for a specific audience and scope.
6566
///

Auth0UniversalComponentsTests/Mocks/MockTokenProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct MockTokenProvider: TokenProvider {
1010

1111
func storeCredentials(credentials: Credentials) {}
1212

13-
func store(apiCredentials: APICredentials, for audience: String) {}
13+
func store(apiCredentials: APICredentials, for audience: String, andScope scope: String) {}
1414

1515
func fetchAPICredentials(audience: String, scope: String) async throws -> APICredentials {
1616
APICredentials(accessToken: "mock-access-token", tokenType: "Bearer", expiresIn: Date(), scope: "openid profile offline_access")

0 commit comments

Comments
 (0)