Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 1000
user3259804 Avatar asked Mar 25 '26 00:03

user3259804


1 Answers

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.

like image 166
MvdD Avatar answered Mar 27 '26 14:03

MvdD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!