0

The email address is contained in the account information, but is not found in the response to the /oauth2/v3/tokeninfo API call from the Huawei Account Server. Why?

Description

After integrating HUAWEI Account Kit, I call the /oauth2/v3/tokeninfo API of the Huawei Account Server to obtain the ID token, but cannot find the email address in the response body. The response in this case is as follows:

{
  "at_hash": "XXXXXX",
  "aud": "XXXXXX",
  "sub": "XXXXXX",
  "azp": "XXXXXX",
  "kid": "XXXXXX",
  "iss": "https://accounts.huawei.com",
  "typ": "JWT",
  "exp": 1579682457,
  "display_name": "338******53",
  "iat": XXXXXX,
  "alg": "RS256"
}

The response in the API reference is as follows:

Figure 1 Response upon a call success enter image description here

4

1 回答 1

1

Before obtaining the ID token, the app does not request the HUAWEI ID user to authorize the app to obtain the email address.

Solution:

Perform the following operations on the device:

(HMS SDK 3.0)

mSignInOptions = new HuaweiIdSignInOptions.Builder(HuaweiIdSignInOptions.DEFAULT_SIGN_IN).requestServerAuthCode().requestIdToken("").requestEmail().build();

(HMS SDK 4.0)

HuaweiIdAuthParams authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM).setIdToken().setEmail().createParams();

The requestEmail() method in HMS SDK 3.0 and the setEmail() method in HMS SDK 4.0 are used to request the HUAWEI ID user to authorize the app to obtain the email address. The two methods must be added to the code on the device in advance.

Tips:

For details about how to request a HUAWEI ID user to authorize an app to obtain related information, visit the following link:

https://developer.huawei.com/consumer/en/doc/HMS-References/account-huaweiidauthparamsHelper#setEmail

于 2020-05-19T06:59:11.877 回答