<legend id='UiLlQ'><style id='UiLlQ'><dir id='UiLlQ'><q id='UiLlQ'></q></dir></style></legend>
    • <bdo id='UiLlQ'></bdo><ul id='UiLlQ'></ul>
  • <tfoot id='UiLlQ'></tfoot>

    <small id='UiLlQ'></small><noframes id='UiLlQ'>

    1. <i id='UiLlQ'><tr id='UiLlQ'><dt id='UiLlQ'><q id='UiLlQ'><span id='UiLlQ'><b id='UiLlQ'><form id='UiLlQ'><ins id='UiLlQ'></ins><ul id='UiLlQ'></ul><sub id='UiLlQ'></sub></form><legend id='UiLlQ'></legend><bdo id='UiLlQ'><pre id='UiLlQ'><center id='UiLlQ'></center></pre></bdo></b><th id='UiLlQ'></th></span></q></dt></tr></i><div id='UiLlQ'><tfoot id='UiLlQ'></tfoot><dl id='UiLlQ'><fieldset id='UiLlQ'></fieldset></dl></div>

      1. Azure AD B2C 以编程方式获取令牌以进行单元测试

        时间:2023-10-25

      2. <tfoot id='CwqHc'></tfoot>

        1. <i id='CwqHc'><tr id='CwqHc'><dt id='CwqHc'><q id='CwqHc'><span id='CwqHc'><b id='CwqHc'><form id='CwqHc'><ins id='CwqHc'></ins><ul id='CwqHc'></ul><sub id='CwqHc'></sub></form><legend id='CwqHc'></legend><bdo id='CwqHc'><pre id='CwqHc'><center id='CwqHc'></center></pre></bdo></b><th id='CwqHc'></th></span></q></dt></tr></i><div id='CwqHc'><tfoot id='CwqHc'></tfoot><dl id='CwqHc'><fieldset id='CwqHc'></fieldset></dl></div>
              <tbody id='CwqHc'></tbody>

            • <legend id='CwqHc'><style id='CwqHc'><dir id='CwqHc'><q id='CwqHc'></q></dir></style></legend>
                <bdo id='CwqHc'></bdo><ul id='CwqHc'></ul>

                  <small id='CwqHc'></small><noframes id='CwqHc'>

                  本文介绍了Azure AD B2C 以编程方式获取令牌以进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的场景很简单,我有一个带有 B2C 身份验证的简单 Azure 函数,我正在编写单元测试,但我发现了一个问题,我无法以编程方式对 azure 函数进行身份验证.

                  My scenario is simple I have a simple Azure Function with B2C authentication on it and I'm writing unit tests but I found an issue, I'm not able to authenticate to the azure functions programmatically.

                  我可以通过浏览器访问,甚至可以获取令牌并将其放入单元测试中,它工作正常,但是当我尝试使用 ClientID、TenantID 等生成令牌时,我得到一个令牌,但在 Azure 函数上出现 401 Unauthorized response.

                  I'm able to access through the browser and even I can grab the token and put it into the unit test and it works fine, but when I try to generate a token using the ClientID, TenantID, etc. I get a token, but 401 Unauthorized response on the Azure functions.

                  有没有办法以编程方式生成有效的 B2C 令牌(无需在浏览器中登录?

                  我目前使用的方法:

                  public static async  Task<AuthenticationResult> GetAccessToken(string resourceUri, string clientId, string clientSecret)
                  {
                          ClientCredential clientCredential = new ClientCredential(clientId, clientSecret);
                  
                          string aadInstance = "https://login.microsoftonline.com/";
                          string tenant = "<mytenant>.onmicrosoft.com";
                          string authority = string.Concat(aadInstance, tenant);
                          AuthenticationContext authContext = new AuthenticationContext(authority);
                  
                          return await authContext.AcquireTokenAsync(resourceUri, clientCredential);
                  }
                  

                  我得到一个令牌 (EY.......) 但无效,当我传递给 Azure 函数请求时,它返回 401 Unauthorized.

                  I'm getting a token (EY.......) but is not valid, when I passed to the Azure Function request, it returns 401 Unauthorized.

                  提前致谢!伊万

                  推荐答案

                  几个月前,Microsoft 发布了资源所有者密码凭据流策略,使用该策略您可以模拟登录,并在查询中传递登录详细信息:如下:

                  A couple of months ago, Microsoft released a policy for resource owner password credentials flow, with that policy you can simulate a login passing the login details in a query as follows:

                  1. 在 B2C 中创建 ROPC 策略
                  2. 注册申请
                  3. 按如下方式测试策略:

                  1. Create a ROPC policy in B2C
                  2. Register an application
                  3. Test the policy as follows:

                    https://te.cpim.windows.net/{B2C TENANT}/{ROPC B2C POLICY}/oauth2/v2.0/token?username={USERNAME}&password={password}&grant_type=password&scope=openid+{CLIENT ID}+offline_access&client_id=[CLIENT ID]&response_type=token+id_token
                  

                  您可以找到更详细的信息 这里

                  You can find more detailed info here

                  这篇关于Azure AD B2C 以编程方式获取令牌以进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:为什么 Azure Function v2 无法绑定到 CloudTable? 下一篇:从另一个 Azure Function 启动 Azure Function 的最佳实践

                  相关文章

                  • <bdo id='cRlsO'></bdo><ul id='cRlsO'></ul>
                  <legend id='cRlsO'><style id='cRlsO'><dir id='cRlsO'><q id='cRlsO'></q></dir></style></legend>

                    <i id='cRlsO'><tr id='cRlsO'><dt id='cRlsO'><q id='cRlsO'><span id='cRlsO'><b id='cRlsO'><form id='cRlsO'><ins id='cRlsO'></ins><ul id='cRlsO'></ul><sub id='cRlsO'></sub></form><legend id='cRlsO'></legend><bdo id='cRlsO'><pre id='cRlsO'><center id='cRlsO'></center></pre></bdo></b><th id='cRlsO'></th></span></q></dt></tr></i><div id='cRlsO'><tfoot id='cRlsO'></tfoot><dl id='cRlsO'><fieldset id='cRlsO'></fieldset></dl></div>

                      <small id='cRlsO'></small><noframes id='cRlsO'>

                    1. <tfoot id='cRlsO'></tfoot>