Erik Robertson
10/09/2021, 1:50 AMnpx aws-api-gateway-cli-test
Now my question is do I make authenticated calls to the api from my client browser. I do not want to use Amplify. So far I have managed to login and fetch tokens using amazon-cognito-identity-js which is all very nice and gives me access+id+refresh tokens but once I have that how do I wrap things up to properly call the /private entrypoint in my API ?
Thanks !Chad (cysense)
10/09/2021, 3:48 AMChad (cysense)
10/09/2021, 3:55 AMFrank
Frank
Erik Robertson
10/09/2021, 9:34 AMChad (cysense)
10/09/2021, 9:50 AMChad (cysense)
10/09/2021, 9:51 AMChad (cysense)
10/09/2021, 9:51 AMasync () => {
const authSession = await Auth.currentSession()
return authSession.getIdToken().getJwtToken();
})
Chad (cysense)
10/09/2021, 9:53 AMBearer Token
and provide the idToken
Erik Robertson
10/09/2021, 10:21 AMdefaultAuthorizationType: sst.ApiAuthorizationType.AWS_IAM,
is that appropriate ?Chad (cysense)
10/09/2021, 10:22 AMsst.ApiAuthorizationType.COGNITO
Chad (cysense)
10/09/2021, 10:24 AMApiAuthorizationType.JWT
in SSTChad (cysense)
10/09/2021, 10:26 AMJWT
authorization construct, so you would probably be better off using CDK for now instead of the SST Auth structChad (cysense)
10/09/2021, 11:01 AMAWS_IAM
should work if you've followed the tutorial. What error are you getting when you try to make an API request?Erik Robertson
10/09/2021, 11:17 AM_const_ auth = new sst.Auth(this, "Auth", {
cognito: {
userPool: {
signInAliases: { email: true },
},
},
});
_const_ api = new sst.Api(this, "Api", {
defaultAuthorizationType: sst.ApiAuthorizationType.JWT,
defaultAuthorizer: new HttpUserPoolAuthorizer({
userPool : auth.cognitoUserPool,
userPoolClient : auth.cognitoUserPoolClient
}),
And It passes through auth with both the access and ID token !
This will probably lead to other questions (around tying things up with IAM perms if possible, getting a unique ID forr the user if in the future we add social logins) but for now I'm happy that I can at least call my API š
We could also investigate why it didn't work with AWS_IAM if I can help out with that. But I'm actually happy with JWT.Frank
AWS_IAM
should definitely work. How are you calling the API in your frontend? If you are coming from the guide, this chapter has some code snippet.Henry Gomez
05/04/2022, 5:29 PMHenry Gomez
05/04/2022, 5:33 PMFrank
Frank
auth.attachPermissionsForAuthUsers([api])
Henry Gomez
05/18/2022, 2:07 AM