-
Notifications
You must be signed in to change notification settings - Fork 317
/
DefaultServerUrls.cs
57 lines (49 loc) · 1.49 KB
/
DefaultServerUrls.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
57
// Copyright (c) Duende Software. All rights reserved.
// See LICENSE in the project root for license information.
using Duende.IdentityServer.Extensions;
using Microsoft.AspNetCore.Http;
using System;
using System.Linq;
namespace Duende.IdentityServer.Services;
/// <summary>
/// Implements IServerUrls
/// </summary>
public class DefaultServerUrls : IServerUrls
{
private readonly IHttpContextAccessor _httpContextAccessor;
/// <summary>
/// ctor
/// </summary>
public DefaultServerUrls(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
/// <inheritdoc/>
public string Origin
{
get
{
var request = _httpContextAccessor.HttpContext.Request;
return request.Scheme + "://" + request.Host.ToUriComponent();
}
set
{
var split = value.Split(new[] { "://" }, StringSplitOptions.RemoveEmptyEntries);
var request = _httpContextAccessor.HttpContext.Request;
request.Scheme = split.First();
request.Host = new HostString(split.Last());
}
}
/// <inheritdoc/>
public string BasePath
{
get
{
return _httpContextAccessor.HttpContext.Items[Constants.EnvironmentKeys.IdentityServerBasePath] as string;
}
set
{
_httpContextAccessor.HttpContext.Items[Constants.EnvironmentKeys.IdentityServerBasePath] = value.RemoveTrailingSlash();
}
}
}