Search code examples
androidsdkaws-api-gatewayamazon-cognitoaws-userpools

How to use auth with CognitoUserSession and ApiClientFactory?


I'm trying to authenticate against an Amazon Cognito Api, however it's not working...


Creating a CognitoUserPool for registering and signing in works. But how to proceed form here on?

In onSuccess(cognitoUserSession: CognitoUserSession) gives me a session, from which I can get a jwtToken (userSession.accessToken.jwtToken).

How to use the session in combination with the ApiFactor?

val api: DevetrackcommercialplaygroundClient = ApiClientFactory()
            .apiKey(apiKey)
            .build(Client::class.java)

        val get= api.getFoo("id") // no auth; works
        val post = api.postBar("id", something) // has auth; doesn't work

Always gives me 401. Both, if I set apiKey to the api key and also if I set it to the jwtToken.

So how can I use CognitoUserSession and ApiClientFactory in conjunction?


Solution

  • Seems like ApiGateway is not really meant to be used with user pools as the whole requests would needs to be created manually without any help from the sdk - same goes for the response.
    See https://github.com/aws-amplify/aws-sdk-android/issues/767

    Maybe this will change at some point in the future:

    I agree with you that the Auth integration with API Gateway is not developer friendly and easy to use. We will take this feedback to the team to investigate on how to improve this integration. - kvasukib