-
Notifications
You must be signed in to change notification settings - Fork 202
/
AuthorityHelpers.cs
41 lines (36 loc) · 1.28 KB
/
AuthorityHelpers.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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using Microsoft.AspNetCore.Http;
namespace Microsoft.Identity.Web
{
internal static class AuthorityHelpers
{
internal static string BuildAuthority(MicrosoftIdentityOptions options)
{
Uri baseUri = new Uri(options.Instance);
string pathBase = baseUri.PathAndQuery.TrimEnd('/');
var domain = options.Domain;
var tenantId = options.TenantId;
// If there are user flows, then it must build a B2C authority
if (options.IsB2C)
{
var userFlow = options.DefaultUserFlow;
return new Uri(baseUri, new PathString($"{pathBase}/{domain}/{userFlow}/v2.0")).ToString();
}
else
{
return new Uri(baseUri, new PathString($"{pathBase}/{tenantId}/v2.0")).ToString();
}
}
internal static string EnsureAuthorityIsV2(string authority)
{
authority = authority.Trim().TrimEnd('/');
if (!authority.EndsWith("v2.0", StringComparison.InvariantCulture))
{
authority += "/v2.0";
}
return authority;
}
}
}