Skip to content

Instantly share code, notes, and snippets.

@cobysy
Created August 5, 2022 11:01
Show Gist options
  • Save cobysy/2cefda807a83bd845d6f0868b2e20630 to your computer and use it in GitHub Desktop.
Save cobysy/2cefda807a83bd845d6f0868b2e20630 to your computer and use it in GitHub Desktop.
PublicClientApplicationBuilder - get token for current user msal.net
var result = await PublicClientApplicationBuilder.CreateWithApplicationOptions(options: new()
{
ClientId = "8bxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
TenantId = "1exxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
})
.WithRedirectUri(redirectUri: "http://localhost")
.Build()
.AcquireTokenInteractive(scopes: "api://7fxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/some.web.api openid profile offline_access".Split(separator: ' '))
.WithAccount(account: PublicClientApplication.OperatingSystemAccount)
.WithPrompt(prompt: Prompt.NoPrompt)
.WithExtraHttpHeaders(extraHttpHeaders: new Dictionary<string, string>
{
{"Origin", "http://localhost"}
})
.ExecuteAsync();
return result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment