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

AWS Lambda authorization for AWS AppSync #1828

Open
1 task done
rezab777 opened this issue Jul 15, 2022 · 3 comments
Open
1 task done

AWS Lambda authorization for AWS AppSync #1828

rezab777 opened this issue Jul 15, 2022 · 3 comments
Labels
api feature-parity Feature missing from this library but available on other ones feature-request Request a new feature GraphQL API Related to the API (GraphQL) category/plugins

Comments

@rezab777
Copy link

rezab777 commented Jul 15, 2022

Before opening, please confirm:

Language and Async Model

Not applicable

Amplify Categories

GraphQL API

Gradle script dependencies

// Put output below this line

Environment information

# Put output below this line


Please include any relevant guides or documentation you're referencing

No response

Describe the feature request

Hello
It's been almost almost a year now that Lambda authorization for AWS AppSync has been released.
We have implemented Lambda auth for our web app but would like to be able to use Lambda authorization for our mobile apps as well.
Could you please provide an ETA of when AWS Lambda authorizer configuration will be added to amplify-android?

Initialization steps (if applicable)

No response

Code Snippet

// Put your code below this line.

amplifyconfiguration.json

No response

GraphQL Schema

// Put your schema below this line

Additional information and screenshots

No response

@sdhuka sdhuka added GraphQL API Related to the API (GraphQL) category/plugins feature-request Request a new feature labels Jul 19, 2022
@lawmicha lawmicha added the api label Sep 7, 2022
@abdallahshaban557 abdallahshaban557 added the feature-parity Feature missing from this library but available on other ones label Oct 25, 2022
@yaroslav-v
Copy link

Hi there!

Is anyone working with this feature request right now?

As far as I can see, AWS lambda auth for DataStore (GraphQL API) is currently available in Amplify Android v2. There's more info regarding this https://docs.amplify.aws/android/build-a-backend/graphqlapi/customize-authz-modes/#aws-lambda

However, there's a problem with configuring this authentication type. The current implementation demands to provide an auth token to ApiAuthProviders when adding AWSApiPlugin which is followed by Amplify.configure call.

As far as we can't call Amplify.configure more than once in Android library, there's no option to provide a different auth token for AWSApiPlugin.

There's a need to improve the current implementation and allow to set a different auth token or call Amplify.configure to provide a new configuration.

Here is a code example:

ApiAuthProviders authProviders = ApiAuthProviders.builder()
    .functionAuthProvider(() -> "[AWS-LAMBDA-AUTH-TOKEN]")
    .build();
AWSApiPlugin plugin = AWSApiPlugin.builder()
    .apiAuthProviders(authProviders)
    .build();
Amplify.addPlugin(plugin); // Can't add or remove a plugin after Amplify.configure was called

AmplifyConfiguration amplifyConfig = AmplifyConfiguration.builder(context)
    .devMenuEnabled(false)
    .build();
Amplify.configure(amplifyConfig, context); // Can't call more than once

@tylerjroach
Copy link
Member

@yaroslav-v The method does not require an auth token, it requires giving a provider.

.functionAuthProvider(() -> "[AWS-LAMBDA-AUTH-TOKEN]") This example has a static token.

I believe what you are asking to do is already possible.

private static final class MyFunctionAuthProvider implements FunctionAuthProvider {

    @Override
    public String getLatestAuthToken() {
        String token = // Implement logic here to determine token to provide
        return token
    }
}

Of course, you can also just inline the logic inside the lambda as is used in the original code example.

@yaroslav-v
Copy link

@tylerjroach Thanks. That's right, I've completely missed the point that this is a provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api feature-parity Feature missing from this library but available on other ones feature-request Request a new feature GraphQL API Related to the API (GraphQL) category/plugins
Projects
None yet
Development

No branches or pull requests

6 participants