user3259804
user3259804

Reputation: 41

Azure Native Client Authentication

I have created a native app on Azure but I'm not sure how to get the access token with just the client ID. I was using a web app earlier in which I had a client ID and secret and used those to authenticate. I've tried using AcquireTokenSilentlyAsync but I cant do that.

Upvotes: 3

Views: 164

Answers (1)

MvdD
MvdD

Reputation: 23436

You can use the AcquireToken method like below. This will pop up a browser dialog to ask for your credentials.

private static string GetToken(string authority, string clientId, string redirectUri)
{
    var authContext = new AuthenticationContext(authority, validateAuthority: false);
    var result = authContext.AcquireToken("https://graph.windows.net",
        clientId, new Uri(redirectUri), PromptBehavior.Auto);

    return result.AccessToken;
}

If you want to authenticate without prompting the user, have a look at the resource owner credential grant. This is explained in this article by Vittorio Bertocci.

Upvotes: 1

Related Questions