3

I am trying to get a ActiveDirectoryClient in a C# client, like this:

 Uri servicePointUri = new Uri("https://graph.microsoft.com/v1.0/me/messages");
 Uri serviceRoot = new Uri(servicePointUri, <OUR-AZURE-TENANT-ID>);
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot,
                    async () => await AcquireTokenAsyncForUser());

With this AcquireTokenAsyncForUser() method:

public static async Task<string> AcquireTokenAsyncForUser()
    {
        return await GetTokenForUser();
    }


    public static async Task<string> GetTokenForUser()
    {
        if (TokenForUser == null)
        {

            AuthenticationContext authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/common/v2.0");
            UserPasswordCredential userCredential = new UserPasswordCredential("<USERNAME>@outlook.com", <PASSWORD>);

            AuthenticationResult userAuthnResult = await authenticationContext.AcquireTokenAsync("https://graph.microsoft.com/v1.0/me/messages",
                <AZURE AD APP CLIENT ID>, userCredential);

            TokenForUser = userAuthnResult.AccessToken;
            Console.WriteLine("\n Welcome " + userAuthnResult.UserInfo.GivenName + " " +
                              userAuthnResult.UserInfo.FamilyName);
        }
        return TokenForUser;
    }

I keep getting this error:

Error getting signed in user accessing_ws_metadata_exchange_failed: Accessing WS metadata exchange failed-

Response status code does not indicate success: 406 (NotAcceptable).-

It does not matter if I use correct or incorrect credentials.

mpjjonker
  • 917
  • 1
  • 6
  • 28

1 Answers1

2

AAD does not support WS-Trust sign in for MSA accounts. You have to sign in the user via webview by calling

AcquireTokenAsync("https://graph.microsoft.com/v1.0/me/messages",
                <AZURE AD APP CLIENT ID>, new Uri("<your redirect uri>", new PlatformParameters(PromptBehavior.Auto{or whatever you want}, null));
Kanishk Panwar
  • 1,105
  • 8
  • 7
  • thanks for your response, what do I do when there is no browser/UI on the device where this code is running ? Should I consider using an Office365 account ? – mpjjonker Nov 02 '16 at 06:49
  • 1
    you can use device code flow as demonstrated T http://www.cloudidentity.com/blog/2015/12/02/new-adal-3-x-previewdevice-profile-linux-and-os-x-sample/ – Kanishk Panwar Nov 02 '16 at 20:05