久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C# ADAL AcquireTokenAsync() 沒(méi)有彈出框

C# ADAL AcquireTokenAsync() without pop-up box(C# ADAL AcquireTokenAsync() 沒(méi)有彈出框)
本文介紹了C# ADAL AcquireTokenAsync() 沒(méi)有彈出框的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我們正在編寫(xiě)一個(gè) WCF 服務(wù),該服務(wù)必須與 Dynamics CRM 2016 Online 集成.我正在嘗試使用 ADAL 進(jìn)行身份驗(yàn)證,使用方法 AcquireTokenAsync().問(wèn)題是,它會(huì)顯示一個(gè)彈出框,提示用戶輸入憑據(jù).當(dāng)然,我們的應(yīng)用程序是一項(xiàng)服務(wù),這不是我們想要的.我們一直在尋找一種無(wú)需此彈出框即可進(jìn)行身份驗(yàn)證的方法.

We are writing a WCF service which has to integrate with Dynamics CRM 2016 Online. I'm trying to authenticate using ADAL, using method AcquireTokenAsync(). Problem is, it displays a pop-up box, prompting the user for credentials. Naturally, our application being a service, this isn't what we want. We've been searching for a way to authenticate without having this pop-up box.

有一個(gè)名為 AuthenticationContextIntegratedAuthExtensions 的類,它應(yīng)該幫助用戶名/密碼流".它有一個(gè)方法 AcquireTokenAsync,它抑制了彈出框,但我們還沒(méi)有找到任何方法來(lái)將密碼傳遞給它.當(dāng)只使用用戶名運(yùn)行時(shí),它會(huì)引發(fā)異常,基本上說(shuō)沒(méi)有提供密碼".

There is a class called AuthenticationContextIntegratedAuthExtensions, which is supposed to assist with "username/password flow". It has the single method AcquireTokenAsync, which suppresses the pop-up box, but we haven't found any way to pass the password to it. When run with just the username, it raises the exception that basically says "no password was supplied".

有誰(shuí)知道如何解決這個(gè)問(wèn)題?甚至不必是 ADAL.只是為了獲取 OAuth 令牌.

Does anyone have any idea how to work around this? Doesn't even have to be ADAL. Just something to acquire the OAuth token.

推薦答案

private static string API_BASE_URL = "https://<CRM DOMAIN>.com/";
private static string API_URL = "https://<CRM DOMAIN>.com/api/data/v8.1/";
private static string CLIENT_ID = "<CLIENT ID>";

static void Main(string[] args)
{
    var ap = AuthenticationParameters.CreateFromResourceUrlAsync(
                new Uri(API_URL)).Result;

    var authContext = new AuthenticationContext(ap.Authority, false);

    var userCredential = new UserCredential("<USERNAME>", "<PASSWORD>");

    var result = authContext.AcquireToken(API_BASE_URL, CLIENT_ID, userCredential);

    var httpClient = HttpWebRequest.CreateHttp(Path.Combine(API_URL, "accounts"));
    httpClient.Headers.Add(HttpRequestHeader.Authorization, "Bearer:" + result.AccessToken);
    using (var sr = new StreamReader(httpClient.GetResponse().GetResponseStream()))
    {
        Console.WriteLine(sr.ReadToEnd());
    }
}

注意:我使用的是舊版 ADAL (2.19.208020213),因?yàn)槊艽a參數(shù)已從 UserCredential 構(gòu)造函數(shù)中取出.

Note: I'm using an older version of ADAL (2.19.208020213) as it appears the password parameter has been taken out of the UserCredential constructor.

最新版本的 ADAL 具有 UserPasswordCredential 可以代替 UserCredential 使用(并且可能在 Password 已從 UserCredential 中刪除)

Latest versions of ADAL have UserPasswordCredential which can be used in place of UserCredential (and probably was added as soon as Password was removed from UserCredential)

編輯 2: CRM 現(xiàn)在支持 服務(wù)器到服務(wù)器身份驗(yàn)證,它允許您創(chuàng)建應(yīng)用程序用戶.

EDIT 2: CRM now supports Server to Server Authentication which allows you to create an application user.

這篇關(guān)于C# ADAL AcquireTokenAsync() 沒(méi)有彈出框的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應(yīng)該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒(méi)有更高效的語(yǔ)法?)
How to set null value to int in c#?(如何在c#中將空值設(shè)置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時(shí)如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調(diào)用)
主站蜘蛛池模板: 日日摸夜夜添夜夜添精品视频 | 男女在线免费观看 | 久久日韩精品 | av在线一区二区 | 亚洲激情在线 | 色伊人网| 91免费在线看| v亚洲 | 日韩激情在线 | 亚洲最大av网站 | 欧美一区二区三区在线 | 日韩成人| 91操操操| 亚洲一区二区在线播放 | 欧美成人精品激情在线观看 | 久草欧美 | 国产亚洲日本精品 | 成人免费共享视频 | 最新国产精品精品视频 | 99久久久国产精品 | 亚洲a视频 | 成人片网址 | 久久国产精品一区二区三区 | 黄色欧美大片 | 亚洲精品久久久一区二区三区 | 成人1区2区 | 欧美日韩在线综合 | 日韩免费视频一区二区 | 国产1区2区在线观看 | 九九伊人sl水蜜桃色推荐 | 国产精品国产自产拍高清 | 精品亚洲国产成av人片传媒 | 欧美一区二区三区四区五区无卡码 | 国产精品久久久久aaaa九色 | 91成人| 视频一区中文字幕 | 国产一级在线观看 | 日韩视频国产 | 91精品国产91久久久久久密臀 | 7777在线视频免费播放 | 天天视频一区二区三区 |