2017-08-10 9 views
0

ログインページにリダイレクトせずにコンソールアプリケーションのAzureアクティブディレクトリに対してユーザーを認証するにはどうすればよいですか?あなたのコード(authenticationContext.AcquireTokenAsync(リソース、clientCred))でAzure Active Directoryに対してユーザーを認証する方法

string tenantName = "---"; 
string authString = "https://login.microsoftonline.com/" + tenantName; 
AuthenticationContext authenticationContext = new AuthenticationContext(authString, false); 
// Config for OAuth client credentials 
string clientId = "---"; 
string key = "---"; 
ClientCredential clientCred = new ClientCredential(clientId, key); 
string resource = "https://pwsintsnapitazure.azurewebsites.net"; 
string token; 
AuthenticationResult authenticationResult = authenticationContext.AcquireTokenAsync(resource, clientCred).Result; 
token = authenticationResult.AccessToken; 
+0

私は上記のサンプルコードを試してみましたが、 "ex = {" AADSTS70002:リクエストボディに 'client_secret or client_assertion'というパラメータが含まれている必要があります " –

+0

あなたのコードはクライアントの資格情報フローを使用しています。 ://www.cloudidentity.com/blog/2014/07/08/using-adal-net-to-authenticate-users-via-usernamepassword/)と[ここ](https://blogs.msdn.microsoft.com) Username/Passwordを使ってユーザーを認証する方法については、/ wushuai/2016/09/25/resource-owner-password-credentials-grant-in-azure-ad-oauth /を参照してください)[Here](https://github.com/ Azure-Samples/active-directory-dotnet-native-headless)はコードサンプルです –

+0

RequestMessage = {メソッド:POST、RequestUri: 'https://login.microsoftonline.com/142d56e1-4ab5-4f5d-8140-d3db9fbf4cac/ oauth2/token? '、バージョン:1.1、コンテンツ:System.Net.Http.StringContent、ヘッダー: { 受諾:application/x-www-form-urlencoded コンテンツタイプ:application/x -... –

答えて

0

トークンを取得するクライアントの資格情報のフローを実行しています。このフローでは、アプリケーションはクライアント証明書をOAuth2トークン発行エンドポイントに提示し、その代わりにユーザー情報なしでアプリケーション自体を表すアクセストークンを取得します。

Azureアクティブディレクトリに対してユーザーを認証し、ログインページを表示しない場合は、ユーザー名/パスワードを使用してユーザーを認証する方法については、herehereをクリックしてください。最初のリンクのConstraints & Limitationsセクションに注意してください。

関連する問題