This repository has been archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
OpenIdConnectOptionsConfiguration.cs
56 lines (48 loc) · 2.15 KB
/
OpenIdConnectOptionsConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.using Microsoft.AspNetCore.Authorization;
using System;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.Extensions.Options;
namespace Microsoft.AspNetCore.Authentication.AzureAD.UI
{
internal class OpenIdConnectOptionsConfiguration : IConfigureNamedOptions<OpenIdConnectOptions>
{
private readonly IOptions<AzureADSchemeOptions> _schemeOptions;
private readonly IOptionsMonitor<AzureADOptions> _azureADOptions;
public OpenIdConnectOptionsConfiguration(IOptions<AzureADSchemeOptions> schemeOptions, IOptionsMonitor<AzureADOptions> azureADOptions)
{
_schemeOptions = schemeOptions;
_azureADOptions = azureADOptions;
}
public void Configure(string name, OpenIdConnectOptions options)
{
var azureADScheme = GetAzureADScheme(name);
var azureADOptions = _azureADOptions.Get(azureADScheme);
if (name != azureADOptions.OpenIdConnectSchemeName)
{
return;
}
options.ClientId = azureADOptions.ClientId;
options.ClientSecret = azureADOptions.ClientSecret;
options.Authority = new Uri(new Uri(azureADOptions.Instance), azureADOptions.TenantId).ToString();
options.CallbackPath = azureADOptions.CallbackPath ?? options.CallbackPath;
options.SignedOutCallbackPath = azureADOptions.SignedOutCallbackPath ?? options.SignedOutCallbackPath;
options.SignInScheme = azureADOptions.CookieSchemeName;
options.UseTokenLifetime = true;
}
private string GetAzureADScheme(string name)
{
foreach (var mapping in _schemeOptions.Value.OpenIDMappings)
{
if (mapping.Value.OpenIdConnectScheme == name)
{
return mapping.Key;
}
}
return null;
}
public void Configure(OpenIdConnectOptions options)
{
}
}
}