Skip to content

feat+fix(lambda): allow access to access jwt in lambda #8023

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

Merged
merged 2 commits into from
Sep 15, 2021

Conversation

NamanJain8
Copy link
Contributor

@NamanJain8 NamanJain8 commented Sep 14, 2021

Feature:
This change makes X-Dgraph-AccessToken accessible to the lambda via accessToken argument. This can help users to extract the User ID from there and taking the relevant actions.
Example script:

function parseJwt (token) {
    var base64Url = token.split('.')[1];
    var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
    var jsonPayload = decodeURIComponent(atob(base64).split('').map(function(c) {
        return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
    }).join(''));

    return JSON.parse(jsonPayload);
};

async function newMovie({args, accessToken, graphql}) {
	console.log(parseJwt(accessToken))
        // Output: {"exp":1631636949,"groups":["guardians"],"namespace":0,"userid":"groot"}
        // Do work.
        return result.data.addMovie.movie[0]
}

self.addGraphQLResolvers ({
    "Mutation.newMovie": newMovie
})

Fix:
Earlier, we used statically generated env.AUTH_TOKEN to pass the credentials from Dgraph to lambda. This would not work with the current implementation of lambda. Here, we need to pass X-Dgraph-AccessToken.


This change is Reviewable

@NamanJain8 NamanJain8 merged commit c668fef into master Sep 15, 2021
@NamanJain8 NamanJain8 deleted the naman/lambda-jwt branch September 15, 2021 05:38
NamanJain8 added a commit that referenced this pull request Sep 15, 2021
* feat+fix(lambda): allow access to access jwt in lambda

* remove usage of env.AUTH_TOKEN

(cherry picked from commit c668fef)
NamanJain8 added a commit that referenced this pull request Sep 15, 2021
Feature:
This change makes X-Dgraph-AccessToken accessible to the lambda via the accessToken argument. This can help users to extract the User ID from there and taking the relevant actions.

Fix:
Earlier, we used statically generated env.AUTH_TOKEN to pass the credentials from Dgraph to lambda. This would not work with the current implementation of lambda. Here, we need to pass X-Dgraph-AccessToken.

(cherry picked from commit c668fef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants