Reputation: 863
Implemented Azure B2C login.
Suddenly app getting this error. unable to find where the issue is. can anyone help
we are using below source: https://github.com/Azure-Samples/ms-identity-android-java
Below code using for Generate KeyHash
public static void getKeyHash(Context mAppContext){
final String packageName = mAppContext.getPackageName();
try {
final PackageInfo info = mAppContext.getPackageManager().getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
for (final Signature signature : info.signatures) {
final MessageDigest messageDigest = MessageDigest.getInstance("SHA");
messageDigest.update(signature.toByteArray());
final String signatureHash = Base64.encodeToString(messageDigest.digest(), Base64.NO_WRAP);
Log.i("Utils", "signatureHash-->"+signatureHash);
}
} catch (PackageManager.NameNotFoundException | NoSuchAlgorithmException e) {
e.printStackTrace();
Log.e("Utils", "Unexpected error in verifyRedirectUriWithAppSignature()", e);
}
}
Scope having Granted permission and same scope URL using in android code
I forgot offline_access permission after added this permission app working
Upvotes: 2
Views: 6117
Reputation: 16438
I reproduced your issue and resolved it successfully.
It is because you didn't do the admin consent for the API permission on Azure portal.
Please see this line in the official sample code.
public static List<String> getScopes() {
return Arrays.asList(
"https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read");
}
This sample sets the scope as https://fabrikamb2c.onmicrosoft.com/helloapi/demo.read
so that it can acquire an access token for this API.
Firstly, you should add an app registration which represents your web API and expose the API by following Quickstart: Configure an application to expose a web API.
Secondly, you need to add the API permission in your client app registration (its client id is configured in auth_config_b2c.json
file) by following Quickstart: Configure a client application to access a web API.
Now the most important thing is doing the admin consent in Azure portal:
You can click on the permission in Azure portal to see it.
Modify the scope in code to your own scope/permission.
public static List<String> getScopes() {
return Arrays.asList(
"https://allentest001.onmicrosoft.com/api/demo.read");
}
With all the settings configured, we can acquire the access token after signing in.
Upvotes: 7