-
Notifications
You must be signed in to change notification settings - Fork 196
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
feat: support for lambda authorizer #1334
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1334 +/- ##
==========================================
+ Coverage 60.55% 60.62% +0.07%
==========================================
Files 660 662 +2
Lines 19877 19951 +74
==========================================
+ Hits 12036 12095 +59
- Misses 7841 7856 +15
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
@@ -10,12 +10,12 @@ import AWSPluginsCore | |||
import Foundation | |||
import AWSCore | |||
|
|||
struct UserPoolURLRequestInterceptor: URLRequestInterceptor { | |||
struct AuthTokenURLRequestInterceptor: URLRequestInterceptor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed to better reflect its usage (used for CognitoUserPools, OIDC and Lambda)
open func functionAuthProvider() -> AmplifyFunctionAuthProvider? { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we choose the name function
to avoid leaking service implementation detail into the library public API
case amazonCognitoUserPools = "AMAZON_COGNITO_USER_POOLS" | ||
|
||
/// Control access by calling a lambda function, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lambda Auth dev guide hasn't been published yet, I'll add a SeeAlso
section as soon as the guide is available
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Storage/StorageEngine+SyncRequirement.swift
Show resolved
Hide resolved
|
||
public protocol AmplifyAuthTokenProvider { | ||
typealias AuthToken = String | ||
func getLatestAuthToken() -> Result<AuthToken, Error> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's verify that the code path that invokes the token provider wraps any returned error in an Amplify APIError
. If so, then I'm OK leaving this returning Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AuthTokenURLRequestInterceptor
(mutations, queries) wraps the returned error in aAPIError.operationError
OIDCAuthInterceptor
(subscriptions) in case of failure retrieving the token it just skips the auth step and doesn't return/wrap the error
@@ -60,14 +60,21 @@ struct AWSAPIEndpointInterceptors { | |||
"") | |||
} | |||
let provider = BasicUserPoolTokenProvider(authService: authService) | |||
let interceptor = UserPoolURLRequestInterceptor(userPoolTokenProvider: provider) | |||
let interceptor = AuthTokenURLRequestInterceptor(authTokenProvider: provider) | |||
addInterceptor(interceptor) | |||
case .openIDConnect: | |||
guard let oidcAuthProvider = apiAuthProviderFactory.oidcAuthProvider() else { | |||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to throws
per discussion. Add note of changed behavior to CHANGELOG
addInterceptor(interceptor) | ||
case .function: | ||
guard let functionAuthProvider = apiAuthProviderFactory.functionAuthProvider() else { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to throws
per discussion. Add note of changed behavior to CHANGELOG
...yPlugins/API/AWSAPICategoryPlugin/SubscriptionFactory/AWSSubscriptionConnectionFactory.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/Core/AWSPluginsCore/Auth/Configuration/AWSAuthorizationConfiguration.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Storage/StorageEngine+SyncRequirement.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Storage/StorageEngine+SyncRequirement.swift
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments inline, plus:
- Add integ tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkpoint review so I'll have something to baseline against
018fc0c
to
70e3555
Compare
Added API integration tests |
|
||
/// General purpose authenticatication subscriptions interceptor for providers whose only | ||
/// requirement is to provide an authentication token via the "Authorization" header | ||
class AuthenticationTokenAuthInterceptor: AuthInterceptor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is largely based on OIDCAuthInterceptor
.
All the AuthInterceptors
(this one included) share a common logic, we should evaluate if it's feasible to refactor in a common interceptor with customization points that others provider-specific interceptors can use to inject custom logic.
...ICategoryPlugin/Interceptor/SubscriptionInterceptor/AuthenticationTokenAuthInterceptor.swift
Outdated
Show resolved
Hide resolved
...ICategoryPlugin/Interceptor/SubscriptionInterceptor/AuthenticationTokenAuthInterceptor.swift
Outdated
Show resolved
Hide resolved
...ICategoryPlugin/Interceptor/SubscriptionInterceptor/AuthenticationTokenAuthInterceptor.swift
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Storage/StorageEngine+SyncRequirement.swift
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved w/deprecation note
Description of changes:
This PR adds support for a new authorization type supported by AppSync : AWS_LAMBDA.
Customers will be able to use an AWS Lambda function to determine whether to authorize a request based on a custom authorization token.
Similarly to OIDC, customers will be able to provide their own token to Amplify by providing an auth factory, an instance of a type conforming to
APIAuthProviderFactory
, and by overriding thefunctionAuthProvider()
method to return anAmplifyFunctionAuthProvider
as follow:Support for Lambda in DataStore (multi-auth included) is achieved with new
AuthRuleStrategy
andAuthRuleProvider
valuescustom
andfunction
.We've decided to use
custom
as rule strategy for different reasons:Android PR: aws-amplify/amplify-android#1412
AppSync feature request: aws/aws-appsync-community#2
Check points:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.