AuthenticationContext.AcquireTokenAsync使用给定密码崩溃 [英] AuthenticationContext.AcquireTokenAsync crash with a given password

查看:272
本文介绍了AuthenticationContext.AcquireTokenAsync使用给定密码崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!


我有这个"简单"的代码:

 public static async Task< string> RetrieveTokenAsync()
{
var authContext = new AuthenticationContext(" https://login.windows.net/MYTENANT.com/" ;, true,new FileCache());
try
{
AuthenticationResult result = null;
result = await authContext.AcquireTokenAsync(Resource,ClientId,new Uri(RedirectUri),
new PlatformParameters(PromptBehavior.Auto),UserIdentifier.AnyUser," domain_hint = MYTENTANT.com");
if(result == null)
{
抛出新的InvalidOperationException("无法获取JWT令牌");
}
//存储令牌以便重复使用
Console.WriteLine(" AccessToken =" + result.AccessToken);
返回result.AccessToken;
}
catch(exception ex)
{
抛出新的InvalidOperationException("无法检索令牌。",ex);
}
}

static void Main(string [] args)
{
try
{
RetrieveTokenAsync()。等待();
}
}

在未连接到Office 365的计算机上调用await authContext.AcquireTokenAsync并使用属于office365帐户的帐户时然后我输入用户和密码崩溃。


这只发生在那个用户和密码上...如果我使用另一个用户但密码相同,则会发生同样的崩溃。所以似乎问题与我使用的密码有关......很奇怪。这是一个8个字符的简单密码。


我尝试针对不同版本的Identity包进行编译,但它是一样的。


任何线索?


谢谢


解决方案

此问题看起来是否相关?  https://community.powerbi.com/t5/Developer/problem-getting-authentication-token-from-AAD/td-p/333691


它只是一个超时或你从中得到任何错误日志吗?



Hi!

I have this "simple" code:

        public static async Task<string> RetrieveTokenAsync()
        {
            var authContext = new AuthenticationContext("https://login.windows.net/MYTENANT.com/", true, new FileCache());
            try
            {
                AuthenticationResult result = null;
                result = await authContext.AcquireTokenAsync(Resource, ClientId, new Uri(RedirectUri),
                        new PlatformParameters(PromptBehavior.Auto), UserIdentifier.AnyUser, "domain_hint=MYTENTANT.com");
                if (result == null)
                {
                    throw new InvalidOperationException("Failed to obtain the JWT token");
                }
                // store token for reuse
                Console.WriteLine("AccessToken=" + result.AccessToken);
                return result.AccessToken;
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException("Could not retrieve token.", ex);
            }
        }

        static void Main(string[] args)
        {
            try
            {
                RetrieveTokenAsync().Wait();
            }
        }	

When calling await authContext.AcquireTokenAsync in a computer that is not connected to Office 365 and I use an account belonging to an office365 account and I enter the user and password it crashes.

This only happens with that user and password... if I use another user but the same password then there is the same crash. So it seems that the problem is related to the password I use... quite strange. It's a simple password of 8 characters.

I tried compiling it against different versions of the Identity package but it's the same.

Any clue?

Thanks

解决方案

Does this issue look related? https://community.powerbi.com/t5/Developer/problem-getting-authentication-token-from-AAD/td-p/333691

Is it just a timeout or do you get any error logs from this? 


这篇关于AuthenticationContext.AcquireTokenAsync使用给定密码崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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