2017-04-12 7 views
0

こんにちは、私は、GRAPH APIを使用してAzureのActive Directoryアプリに新しいユーザーを追加しようとしていますが、クライアントを構築するために必要なURLはわかりませんC#では、私が確信している唯一の文字列はclientSecretです。 誰でも助けることができますか? this blog postXamarin.Androidアプリ(Azure Active Directory)からユーザーを追加

const string authString = ""; 
    const string clientID = ""; 
    const string clientSecret = ""; 
    const string resAzureGraphAPI = ""; 
    const string serviceRootURL = ""; 
    static Uri serviceRoot = new Uri(serviceRootURL); 
    ActiveDirectoryClient adClient = new ActiveDirectoryClient(
     serviceRoot, 
     async() => await GetAppTokenAsync()); 
    private void But_Click(object sender, EventArgs e) 
    { 
     // Create a new user object. 
     var newUser = new User() 
     { 
      // Required settings 
      DisplayName = "Jay Hamlin", 
      UserPrincipalName = "[email protected]", 
      PasswordProfile = new PasswordProfile() 
      { 
       Password = "[email protected]!", 
       ForceChangePasswordNextLogin = false 
      }, 
      MailNickname = "JayHamlin", 
      AccountEnabled = true, 

      // Some (not all) optional settings 
      GivenName = "Jay", 
      Surname = "Hamlin", 
      JobTitle = "Programmer", 
      Department = "Development", 
      City = "Dallas", 
      State = "TX", 
      Mobile = "214-123-1234", 
     }; 

     // Add the user to the directory 
     adClient.Users.AddUserAsync(newUser).Wait(); 
    }` 
    private static async Task<string> GetAppTokenAsync() 
    { 
     // Instantiate an AuthenticationContext for my directory (see authString above). 
     AuthenticationContext authenticationContext = new AuthenticationContext(authString, false); 

     // Create a ClientCredential that will be used for authentication. 
     // This is where the Client ID and Key/Secret from the Azure Management Portal is used. 
     ClientCredential clientCred = new ClientCredential(clientID, clientSecret); 

     // Acquire an access token from Azure AD to access the Azure AD Graph (the resource) 
     // using the Client ID and Key/Secret as credentials. 
     AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resAzureGraphAPI, clientCred); 

     // Return the access token. 
     return authenticationResult.AccessToken; 
    }` 
+0

何が問題ですか?問題の程度を知らなければ、あなたを助けることは困難です。あなたの質問を更新してください。 – Demitrian

+0

const string authString = ""; const string clientID = ""; const string clientSecret = ""; const string resAzureGraphAPI = ""; const string serviceRootURL = ""; 私はこの文字列を埋める方法を知らない –

答えて

0

あなたが探している文字列の通過詳細な散歩を見つけることができます:

  1. authString
    • authoritytokenを返すなります。これは通常、OAuth認証を処理するサードパーティのエンドポイントです。例は次のとおりです。https://login.windows.net/common/oauth2/authorize
  2. clientID
    • これは、グラフAPIへ
  3. resAzureGraphAPI
    • UriポータルAzureのアプリケーションから取得することができます。おそらくhttps://graph.windows.net
  4. serviceRootURL
    • アプリケーションのドメインにUri
    • 。あなたはそれが実行をブロックしますよう AddUserAsync().Wait();を呼び出すことは避けるべき、さらに

のAzure Active Directoryでドメイン]タブの下でこれを見つけることができるはずです。代わりに、結果はawaitである必要があります。

0

最初にAzure Active Directory developer's guideをお読みください。また、使用している場合:

AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resAzureGraphAPI, clientCred); 

は、アクセストークンを取得するには(ユーザーのIDの代わりに)そのアプリIDを使用してAPIを呼び出すことを意味します。 Azure広告ポータルにアプリケーション権限を追加し、権限をユーザーに付与する必要があります。アプリケーション権限を選択すると、アプリケーションでOAuthクライアント資格情報フローを使用してGraph APIを呼び出すことができます(ユーザーは必要ありません)。詳細はhereをクリックしてください。

関連する問題