2017-08-10 12 views
3

これは私がコードを書かれており、出力を取得しようとしている方法ですEX = { "AADSTS70002:リクエストボディには、次のパラメータが含まれている必要があります。『client_secretまたはclient_assertion』

リクエストボディには、次のものが含まれている必要がありますパラメータ:あなたが認証するためのユーザ名とパスワードを使用してWebアプリケーション/ APIを使用しているようで、あなたのコードによると、client_secretまたはclient_assertion

static async Task<AuthenticationResult> getAccessToken() 
{ 
    string hardcodedUsername = ""; 
    string hardcodedPassword = ""; 
    string tenantName = "projectwidgets.com"; 
    string authString = "https://login.microsoftonline.com/" + tenantName; 
    AuthenticationContext authenticationContext = new AuthenticationContext(authString, false); 
    //Config for OAuth client credentials 
    string clientId = "as"; 
    string key = "kk"; 
    string authority = String.Format(CultureInfo.InvariantCulture, aadInstance, tenantName); 
    var authContext = new AuthenticationContext(authority); 
    AuthenticationResult result = null; 
    try 
    { 
     result = await authContext.AcquireTokenAsync("https://pwsnapitazure.azurewebsites.net", clientId, new UserPasswordCredential(hardcodedUsername, hardcodedPassword)); 
    } 
    catch (Exception ex) 
    { 
      Console.WriteLine(ex.StackTrace); 
      System.Diagnostics.Debug.WriteLine(ex.Message); 
    }       
    return result; 
} 

答えて

1

01。

ネイティブクライアントからのリソース所有者フローのみを使用できます。 Webサイトなどの機密クライアントは、直接のユーザー資格情報を使用できません。

機密クライアント(Webアプリケーション/ API)ではなく、公開クライアント(ネイティブクライアントアプリケーション)として呼び出す必要があります。 ADAL .NETを使用してユーザー名/パスワード、特にConstraints & Limitationsセクションを介してユーザーを認証する方法の詳細については、this documentを参照してください。

デーモンまたはサーバーアプリケーションでは、あなたがclient credential flowを使用して検討することは、この流れで、アプリケーションがエンドポイントを発行するのOAuth2トークンにそのクライアントの資格情報を提示し、見返りに任意のユーザー情報なしにアプリケーション自体を表してアクセストークンを取得します。クライアント資格情報フローの詳細については、hereをクリックしてください。hereはコードサンプルです。

関連する問題