身份验证失败:com.microsoft.identity.client.exception.MsalClientException:缺少类型所需的令牌:{0} [英] Authentication failed: com.microsoft.identity.client.exception.MsalClientException: Missing required tokens of type: {0}

查看:112
本文介绍了身份验证失败:com.microsoft.identity.client.exception.MsalClientException:缺少类型所需的令牌:{0}的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实施了 Azure B2C 登录.

应用突然收到此错误.无法找到问题所在.谁能帮忙

我们使用以下来源:

您可以在 Azure 门户中单击该权限进行查看.

将代码中的范围修改为您自己的范围/权限.

public static List获取范围(){返回 Arrays.asList(https://allentest001.onmicrosoft.com/api/demo.read");}

配置好所有设置后,我们可以在登录后获取访问令牌.

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

enter image description here

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

enter image description here

I forgot offline_access permission after added this permission app working

解决方案

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.

这篇关于身份验证失败:com.microsoft.identity.client.exception.MsalClientException:缺少类型所需的令牌:{0}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆