<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 以编程方式获取令牌以进行单元测试

        Azure AD B2C get token programatically for unit testing(Azure AD B2C 以编程方式获取令牌以进行单元测试)

      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 以编程方式获取令牌以进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Adding and removing users from Active Directory groups in .NET(在 .NET 中的 Active Directory 组中添加和删除用户)
                  set equality in linq(在 linq 中设置相等)
                  HashSet conversion to List(HashSet 转换为 List)
                  How to set timeout for webBrowser navigate event(如何为 webBrowser 导航事件设置超时)
                  Test whether two IEnumerablelt;Tgt; have the same values with the same frequencies(测试两个IEnumerablelt;Tgt;具有相同频率的相同值)
                  How do you determine if two HashSets are equal (by value, not by reference)?(您如何确定两个 HashSet 是否相等(按值,而不是按引用)?)

                    • <bdo id='cRlsO'></bdo><ul id='cRlsO'></ul>
                        <tbody id='cRlsO'></tbody>
                      <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'>

                          • <tfoot id='cRlsO'></tfoot>