Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Auth] - Support UserPoolsAuth Provider #3916

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ open class APIAuthProviderFactory {
/// Empty public initializer
public init() {
}


/// Retrieve the UserPools auth provider
open func userPoolsAuthProvider() -> AmplifyUserPoolsAuthProvider? {
return nil
}

/// Retrieve the OIDC auth provider
open func oidcAuthProvider() -> AmplifyOIDCAuthProvider? {
return nil
Expand All @@ -30,6 +35,9 @@ public protocol AmplifyAuthTokenProvider {
func getLatestAuthToken() async throws -> String
}

/// Amplify CognitoUserPools Auth Provider
public protocol AmplifyUserPoolsAuthProvider: AmplifyAuthTokenProvider {}

/// Amplify OIDC Auth Provider
public protocol AmplifyOIDCAuthProvider: AmplifyAuthTokenProvider {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,21 @@ struct AWSAPIEndpointInterceptors {
endpointType: endpointType)
postludeInterceptors.append(interceptor)
case .amazonCognitoUserPools:
guard let authService = authService else {
throw PluginError.pluginConfigurationError("AuthService not set for cognito user pools",
"")
if let userPoolsAuthProvider = apiAuthProviderFactory.userPoolsAuthProvider() {
let wrappedAuthProvider = AuthTokenProviderWrapper(tokenAuthProvider: userPoolsAuthProvider)
let interceptor = AuthTokenURLRequestInterceptor(authTokenProvider: wrappedAuthProvider,
isTokenExpired: expiryValidator)
preludeInterceptors.append(interceptor)
} else {
guard let authService = authService else {
throw PluginError.pluginConfigurationError("AuthService not set for cognito user pools",
"")
}
let provider = BasicUserPoolTokenProvider(authService: authService)
let interceptor = AuthTokenURLRequestInterceptor(authTokenProvider: provider,
isTokenExpired: expiryValidator)
preludeInterceptors.append(interceptor)
}
let provider = BasicUserPoolTokenProvider(authService: authService)
let interceptor = AuthTokenURLRequestInterceptor(authTokenProvider: provider,
isTokenExpired: expiryValidator)
preludeInterceptors.append(interceptor)
case .openIDConnect:
guard let oidcAuthProvider = apiAuthProviderFactory.oidcAuthProvider() else {
throw PluginError.pluginConfigurationError("AuthService not set for OIDC",
Expand Down