Portfolio.Web
1.0.0.0
.NET, Blazor, WPF와 서비스 운영 경험을 프로젝트·이력·기술 스택 단위로 보여주는 개발자 포트폴리오입니다.
Toggle main menu visibility
로딩중...
검색중...
일치하는것 없음
PortfolioUserContext.cs
이 파일의 문서화 페이지로 가기
1
using
System.Security.Claims;
2
using
Dreamine.Identity;
3
using
Microsoft.AspNetCore.Components.Authorization;
4
5
namespace
PortfolioApp.Services
;
6
15
public
sealed
record
PortfolioCurrentUser
(
16
string
Id,
17
string
Provider,
18
string
Email,
19
string
DisplayName)
20
{
29
public
bool
IsAuthenticated => !
string
.IsNullOrWhiteSpace(Id);
30
39
public
static
PortfolioCurrentUser
Anonymous {
get
; } =
new
(
""
,
""
,
""
,
""
);
40
}
41
50
public
sealed
class
PortfolioUserContext
51
{
60
private
readonly AuthenticationStateProvider
_authenticationStateProvider
;
61
78
public
PortfolioUserContext
(AuthenticationStateProvider authenticationStateProvider)
79
{
80
_authenticationStateProvider
= authenticationStateProvider;
81
}
82
99
public
async Task<PortfolioCurrentUser>
GetCurrentAsync
()
100
{
101
var state = await
_authenticationStateProvider
.GetAuthenticationStateAsync().ConfigureAwait(
false
);
102
var principal = state.User;
103
104
if
(principal.Identity?.IsAuthenticated !=
true
)
105
{
106
return
PortfolioCurrentUser
.Anonymous;
107
}
108
109
string
userId = principal.FindFirstValue(DreamineIdentityExtensions.UserIdClaimType) ??
string
.Empty;
110
if
(
string
.IsNullOrWhiteSpace(userId))
111
{
112
return
PortfolioCurrentUser
.Anonymous;
113
}
114
115
string
provider = principal.FindFirstValue(DreamineIdentityExtensions.ProviderClaimType) ??
"Local"
;
116
string
email = principal.FindFirstValue(ClaimTypes.Email) ??
string
.Empty;
117
string
displayName = principal.FindFirstValue(ClaimTypes.Name) ?? email;
118
119
return
new
PortfolioCurrentUser
(
120
$
"oauth-{userId}"
,
121
provider,
122
email,
123
displayName);
124
}
125
}
PortfolioApp.Services
Definition
GhostAccountCleanupService.cs:4
PortfolioApp.Services.PortfolioCurrentUser
record PortfolioCurrentUser(string Id, string Provider, string Email, string DisplayName)
Definition
PortfolioUserContext.cs:15
PortfolioApp.Services.PortfolioUserContext._authenticationStateProvider
readonly AuthenticationStateProvider _authenticationStateProvider
Definition
PortfolioUserContext.cs:60
PortfolioApp.Services.PortfolioUserContext.PortfolioUserContext
PortfolioUserContext(AuthenticationStateProvider authenticationStateProvider)
Definition
PortfolioUserContext.cs:78
PortfolioApp.Services.PortfolioUserContext.GetCurrentAsync
async Task< PortfolioCurrentUser > GetCurrentAsync()
Definition
PortfolioUserContext.cs:99
Services
PortfolioUserContext.cs
다음에 의해 생성됨 :
1.17.0