Get JWT token in GO


I want to implement logic below(in javascript) to get JWT token for a user in GO (Receiving the JWT token from Cognito UserPools).
I looked at but couldn’t find corresponding classes.
Can somebody please guide me how to implement this in GO?


 var authenticationData = {
        Username : 'username',
        Password : 'password',
    var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
    var poolData = { UserPoolId : 'us-east-1_xxxxx',
        ClientId : 'xxxxxxxxxxxxxxxx'
    var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
    var userData = {
        Username : 'username',
        Pool : userPool
    var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
    cognitoUser.authenticateUser(authenticationDetails, {
        onSuccess: function (result) {
            console.log('access token + ' + result.getAccessToken().getJwtToken());
            /*Use the idToken for Logins Map when Federating User Pools with identity pools or when passing through an Authorization Header to an API Gateway Authorizer*/
            console.log('idToken + ' + result.idToken.jwtToken);

        onFailure: function(err) {


Do understand your question correctly: you want to port this JavaScript code to Go? Which JS libraries do you use here and what do they do?

Yes. I want to port this code to Go. I am new to GO and learning.

Here is what I am trying to achieve :-
From GO call AWS Cognito API with username and password to get the JWT token.

I got this sample code from amazon docs example for javascript SDK and that is exactly what I want to achieve in GO.

In GO SDK I couldn’t find similar classes/methods as shown in javascript example, So trying to find mapped class and its methods which will help me achieve the same.

Check out this repository: seems to solve your issue ( )

1 Like

For JWT I use library and jwt middleware in Echo framework.


Just to add, lot of popular JWT middlewares actually use this lib as well.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.