Support Topics Documentation Slack YouTube Blog

Login with oauth2 and amazon

Backendless Version (3.x / 5.x, Online / Managed / Pro )

Online

Client SDK (REST / Android / Objective-C / Swift / JS )

JS

Application ID

8F146EC9-7BA1-8E5E-FF1B-6EABA0EC1200

Expected Behavior

  1. User of my application can use their login from amazon

Actual Behavior

  1. The UserService always returns me the user data from my client user at amazon (login with amazon) and the clients one

Reproducible Test Case

window.amazon.Login.authorize(options, response => {
  if (response.error) {
    return reject(response.error)
  }
  window.amazon.Login.retrieveToken(response.code, response => {
    if (response.error) {
      return reject(response.error)
    }
    console.log(response.access_token)
    Backendless.UserService.loginWithOauth2(
      'amazon',
      response.access_token
    )
    .then(user => {
      console.log('#1 user ', user)
      const token = User.token = response.access_token
      window.amazon.Login.retrieveProfile(token, response => {
        if (response.success === false) {
          User.logout()
        } else {
          console.log('#2 user ', response.profile);
          resolve({ user: response.profile, token });
        }
      })
    })
    .catch(reject)
  })
});

Hi, @Tobias_Oberrauch

Could you provide us what do you have in response now, after invoking the loginWithOauth2 method?

Regards,
Marina

I receive this

with this source code

What I want is to login the user that I receiver from retrieveProfile (tobias.oberrauch@gmx.de) and not that I received from loginWithOauth2 (tobiasoberrauch@gmx.de) <-- without a dot. There a 2 different users

tobiasoberrauch@gmx.de is the user I used for the client configuration for “login with amazon”
tobias.oberrauch@gmx.de is the current user that login in amazon

Hello @Tobias_Oberrauch

It seems like you had changed the email in the Amazon account, or you’ve got two accounts?

Currently we link (backendless/social) users based on the identity column that’s the reason why you might have two separated users in the Users table when you login with the same account but when the account has changed email address. There is an internal ticket BKNDLSS-23399 to improve this and determine the same user buy its socialId.

When my colleague do a login, all the data will assign to me (tobiasoberrauch@gmx.de)
That email that also associated with client id and secret

@vladimir-upirov
Maybe there is a missunderstanding.
When I’m using “Backendless.UserService.loginWithOauth2” it will authenticate my frontend as a valid client not as the current user.
I think I have to use the result of amazon.Login.retrieveProfile and create an user account in Backendless if user not exists.
What do you think?

@Tobias_Oberrauch we were enable to reproduce your issue. There is an internal ticket BKNDLSS-23399 to improve this and determine the same user by its socialId. We will fix it as soon as possible and back to you. Stay in touch.

Regards,
Marina

Hi @Marina.Rudenko

thank you for your answer. Do you have an rough idea how long this could take?
one day, one week, one month?

Can I help you in any way?
I’m a developer and can fix a bug if the library concerned is open source.

We are about to go live and are just waiting for this great feature :slight_smile:
Thank you very much
Tobias

Hello @Tobias_Oberrauch

We cannot say specific dates. I can only say that our developers are already working on the problem, and as soon as it is fixed, we will immediately inform you.

Regards,
Inna

1 Like

Hi,

do you have an update or an outlook for me? :slight_smile:
Thank you

Hi @Tobias_Oberrauch

We are currently working on this issue. As a temporary solution, you can remove user record from backendless console and authorize again with a valid email.

Best Regards,
Maksym

Hi @Maksym_Khobotin2,
the problem is that the new user will be registered with that email address that belongs to my private “login for amazon” account.
When I remove the user record and authorize it again, it will use the wrong email again.

Thanks for your patience, this ticket still in progress, I have increased the priority and notify you when it will be fixed.

Thank you @Dima_Vak. That is very kind.
I wish you and your team a great start into the next year :fireworks:

1 Like

Hi @Tobias_Oberrauch!

Sorry for delay with your question.
To clarify situation. Amazon OAuth2 login provider from templates implements flow from “Login with Amazon”

User information in this flow is taken from route which described here:

If you want to use your custom OAuth2 provider based on Amazon services then you should create your custom OAuth2 provider.

Regards, Andriy

Hi @Andriy_Konoz,

how I can implement my own custom OAuth2 provider in backendless?

Hello @Tobias_Oberrauch

You can add your custom provider in Users>>Login Providers>>Add new login provider: https://monosnap.com/direct/Di8Kp3dUy6lFpN00YJKxu3g1nljGDl

After that add all the necessary parameters, enable the provider and save it.
To get a request url for login through the provider use the following cURL:

curl --location --request POST ‘https://api.backendless.com/APP-ID/API-KEY/users/social/oauth/PROVIDER-NAME/request_url
–header ‘Content-Type: application/json’
–data-raw ‘{
“fieldsMapping”: { “email”: “email” },
“redirect”: false
}’

Regards,
Inna

Hi @Inna_Shkolnaya ,

I just tried it out.


There is a error regarding a missing accessToken.

But I sent the accessToken:

Tobias

Hello @Tobias_Oberrauch

Have you added Amazon as a new custom provider? We are giving our users a more simplified setup for an Amazon provider. All you need to do is add the Client-ID and the Client-secret from the Amazon to backendless console, as well as copy the Request URL and add it to the Amazon configs.

curl --location --request POST ‘https://api.backendless.com/APP-ID/API-KEY/users/social/oauth/amazon/request_url’
–header ‘Content-Type: application/json’
–data-raw ‘{
“fieldsMapping”: { “email”: “email” },
“redirect”: false
}’

This сurl will return you a link to login via Amazon.

Regards,
Inna