Android AWS Pinpoint -User Does Not Match Cognito

49 views Asked by At

Using AWS Pinpoint, I want to connect and send remote notifications when the application is logged in.

I made the necessary connections for this and created my awsconfiguration.json file.

My project includes Cognito, the connection must be established automatically and the user information, sub id, etc. must reach the server. It reaches the server, but the user information does not arrive.

Can you help me ?

awsconfiguration.json file:


"CredentialsProvider": {
    "CognitoIdentity": {
      "Default": {
        "PoolId": "eu-cenxxxxxxXXXXX1cfea",
        "Region": "eu-XXXXX-1",
        "AppClientId": "1rbXXXXXXXXXXg2"
      }
    }
  },
  "CognitoUserPool": {
    "Default": {
      "PinpointAppId": "aXXXXXXXXXXbe40",
      "PoolId": "eu-central-XXXXXG0",
      "AppClientId": "1XXXXXXXXXXcg2",
      "Region": "eu-central-1",
      "AppClientSecret": "1X6XXXXXXXXXXXXXXXXXXXqm"
    }
  },
  "Auth": {
    "Default": {
      "OAuth": {
        "WebDomain": "login-brand-customer-dev.auth.eu-central-1.amazoncognito.com",
        "AppClientId": "1rbeXXXXXXXXXg2",
        "AppClientSecret": "1XXXXXXXXXXXXXXXXXXXX7qm",
        "SignInRedirectURI": "XXX://callback",
        "SignOutRedirectURI": "XXX://signout",
        "Scopes": ["profile", "openid", "email", "aws.cognito.signin.user.admin"]
      }
    }
  },
  "PinpointAnalytics": {
    "Default": {
      "AppId": "abXXXXXXXXXXXX40",
      "Region": "eu-cXXX-1"
    }
  },
  "PinpointTargeting": {
    "Default": {
      "Region": "eXXXral-1"
    }
  }

(I added the X's for privacy.)

and my init code:


override fun initializePinpoint() {
        AWSMobileClient.getInstance().initialize(
            appContext,
            object : Callback<UserStateDetails> {
                override fun onResult(result: UserStateDetails) {
                    test(appContext)
                }
                override fun onError(e: Exception) {
                    logger.e(e) { "Error initializing AWS mobile client" }
                }
            }
        )

private fun test(context: Context) {
        val pinpointManager: PinpointManager
        val firebaseMessaging = FirebaseMessaging.getInstance()
        val id = AWSMobileClient.getInstance().tokens.idToken.getClaim("sub")

        val pinpointConfiguration = PinpointConfiguration(
            context,
            AWSMobileClient.getInstance(),
            AWSMobileClient.getInstance().configuration
        )
        pinpointManager = PinpointManager(pinpointConfiguration)
        pinpointManager.sessionClient.startSession()
        pinpointManager.analyticsClient.submitEvents()

        if (pinpointManager.targetingClient.currentEndpoint().user.userId.isNullOrEmpty()) {
            pinpointManager.targetingClient.currentEndpoint().user.userId = id
        }

        firebaseMessaging.token.addOnCompleteListener { task ->
            if (task.isSuccessful) {
                val fcmToken = task.result
                pinpointManager.notificationClient.registerDeviceToken(fcmToken)
            }
        }
        pinpointManager.targetingClient.updateEndpointProfile()
     
    }

I had to give the id automatically, but it still creates a new endpoint every time, which was not a good solution. Can you please point out my mistake for me? What do I need to know for Cognito and Pinpoint to work together?

0

There are 0 answers