Example #1
0
 public Function(IConfiguration configuration)
 {
     this.configuration     = configuration;
     this.azureAdB2COptions = new AzureAdB2COptions();
     configuration.GetSection(nameof(azureAdB2COptions)).Bind(azureAdB2COptions);
 }
Example #2
0
        public async Task <AuthenticationResult> GetAuthenticationResultAsync(Uri redirectUri, AzureAdB2COptions options)
        {
            IConfidentialClientApplication app = ConfidentialClientApplicationBuilder.Create($"{options.ClientId}")
                                                 .WithRedirectUri(redirectUri.AbsoluteUri)
                                                 .WithClientSecret(options.ClientSecret)
                                                 .WithB2CAuthority(options.Authority)
                                                 .Build();

            // make sure you cannot use Refresh Token with MSAL anymore.
            var scopes = options.ApiScopes.Split(' ');

            // OAuth authorization code is contains in `code`, short live 10min.
            // https://docs.microsoft.com/ja-jp/azure/active-directory-b2c/active-directory-b2c-reference-oauth-code
            var auth = await app.AcquireTokenByAuthorizationCode(scopes, code).ExecuteAsync();

            return(auth);
        }