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

如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的

How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發(fā)技
本文介紹了如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時送ChatGPT賬號..

我已經(jīng)實(shí)現(xiàn)了 Azure AD OAuth2 守護(hù)程序或服務(wù)器到 ASP.NET Web API.但是,我只收到一個訪問令牌,它是 AuthenticationResult 上的屬性.請參閱下面的實(shí)現(xiàn).

 public IHttpActionResult GetAccessToken(string clientId, string clientkey){AuthenticationContext authContext = new AuthenticationContext(authority);ClientCredential clientCredential = new ClientCredential(clientId, clientkey);AuthenticationResult authenticationResult = authContext.AcquireTokenAsync(resourceUri, clientCredential).Result;授權(quán)授權(quán)=新授權(quán){access_token = authenticationResult.AccessToken,token_type = authenticationResult.AccessTokenType,expires_on = authenticationResult.ExpiresOn };返回確定(授權(quán));}

這僅返回訪問令牌.我想要一個實(shí)現(xiàn),一個守護(hù)進(jìn)程或服務(wù)器實(shí)現(xiàn),它返回訪問令牌和刷新令牌.您是否看過或做過類似的實(shí)現(xiàn).歡迎任何有用的示例鏈接.

解決方案

當(dāng)我發(fā)布這個問題時,這就是我正在尋找的答案,請參閱下面的屏幕截圖以了解預(yù)期結(jié)果和 c# 控制臺解決方案.找到解決方案后,值得在這里分享,可能有一天對某人有用

在下面的郵遞員屏幕截圖中實(shí)現(xiàn)預(yù)期結(jié)果的 C# 控制臺應(yīng)用程序代碼

使用系統(tǒng);使用 System.Collections.Generic;使用 System.Net.Http;命名空間 AzureADTokenApp{課堂節(jié)目{靜態(tài)無效主要(字符串 [] 參數(shù)){var client = new HttpClient();var uri = "https://login.microsoftonline.com/<tenant-name>.onmicrosoft.com/oauth2/token?api-version=1.0";var 對 = 新列表<KeyValuePair<字符串,字符串>>{new KeyValuePair<string, string>("resource", "https://graph.microsoft.com"),new KeyValuePair("client_id", "

I have implemented an Azure AD OAuth2 Daemon or Server to ASP.NET Web API. However I only receive an access token which is the property on the AuthenticationResult. See implementation below.

    public IHttpActionResult GetAccessToken(string clientId, string clientkey)
    {
        AuthenticationContext authContext = new AuthenticationContext(authority);
        ClientCredential clientCredential = new ClientCredential(clientId, clientkey);
        AuthenticationResult authenticationResult = authContext.AcquireTokenAsync(resourceUri, clientCredential).Result;
        Authorisation authorisation = new Authorisation {access_token = authenticationResult.AccessToken,
                                                token_type = authenticationResult.AccessTokenType,
                                                expires_on = authenticationResult.ExpiresOn };

        return Ok(authorisation);
    }   

This returns only access token. I would like an implementation, a Daemon or Server implementation that returns both access token and refresh token. Have your seen or done similar implementation. Any useful links to an example are welcome.

解決方案

When I posted this question, this was the answer I was looking for, please see screen shot below for expected result and c# console solution. Having found the solution, it is worth sharing it here, may be useful to someone some day

C# console app code to achieve expected result in the postman screen shot below

using System;
using System.Collections.Generic;
using System.Net.Http;

namespace AzureADTokenApp
{
    class Program
    {
        static void Main(string[] args)
        {

            var client = new HttpClient();
            var uri = "https://login.microsoftonline.com/<tenant-name>.onmicrosoft.com/oauth2/token?api-version=1.0";
            var pairs = new List<KeyValuePair<string, string>>
            {
                new KeyValuePair<string, string>("resource", "https://graph.microsoft.com"),
                new KeyValuePair<string, string>("client_id", "<azure ad client id e.g. 9b864-a5e6-4f0d-b155-1f53a6c78>"),
                new KeyValuePair<string, string>("client_secret", "<azure ad client secret e.g. MTMiXaO1P9HnhSawdXWmcnuQ="),
                new KeyValuePair<string, string>("grant_type", "password"),
                new KeyValuePair<string, string>("username", "<azure ad user e.g. julius.depulla@example.com>"),
                new KeyValuePair<string, string>("password", "<azure ad user password e.g. Pa$$word01>"),
                new KeyValuePair<string, string>("scope", "openid")
             };

            var content = new FormUrlEncodedContent(pairs);

            var response = client.PostAsync(uri, content).Result;

            string result = string.Empty;

            if (response.IsSuccessStatusCode)
            {

                result = response.Content.ReadAsStringAsync().Result;
            }

            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}

Screenshot from Postman - Expected Result. You will have same result in console except is less readable

這篇關(guān)于如何獲取守護(hù)進(jìn)程或服務(wù)器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進(jìn)行身份驗(yàn)證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權(quán)不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調(diào)用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
Getting access token using email address and app password from oauth2/token(使用電子郵件地址和應(yīng)用程序密碼從 oauth2/token 獲取訪問令牌)
主站蜘蛛池模板: 中文字幕 在线观看 | 日韩欧美精品一区 | 91久久久久久久久久久久久 | 国产一区www| 在线91| 色婷婷综合久久久久中文一区二区 | 国产精品久久久久久 | 成人影| 欧美偷偷| 国产91综合 | 日韩欧美中文字幕在线观看 | 亚洲久久 | 亚洲视频 欧美视频 | 国内在线视频 | 日韩精品在线一区 | 一级黄色片免费在线观看 | 少妇黄色| 在线āv视频 | 亚洲一区二区视频在线播放 | 中文日韩在线视频 | 在线免费观看日本视频 | 国产精品美女久久久久aⅴ国产馆 | 正在播放一区二区 | 伊色综合久久之综合久久 | 精品日韩在线 | 日韩精品一区二区三区在线播放 | 精品在线看 | 中文字幕免费在线 | 成人片免费看 | 国产成人在线一区 | 欧美国产亚洲一区二区 | 亚洲精品视频在线播放 | 最新免费视频 | 国产精品久久久久久久粉嫩 | 欧美一区二区在线看 | 青青草综合 | 最新av中文字幕 | 99re6在线视频精品免费 | 午夜影院在线观看 | 在线视频一区二区 | 婷婷色网 |