@@ -70,7 +70,8 @@ public virtual async Task<RemoteAuthenticationResult<TRemoteAuthenticationState>
70
70
RemoteAuthenticationContext < TRemoteAuthenticationState > context )
71
71
{
72
72
await EnsureAuthService ( ) ;
73
- var result = await _jsRuntime . InvokeAsync < RemoteAuthenticationResult < TRemoteAuthenticationState > > ( "AuthenticationService.signIn" , context . State ) ;
73
+ var internalResult = await _jsRuntime . InvokeAsync < InternalRemoteAuthenticationResult < TRemoteAuthenticationState > > ( "AuthenticationService.signIn" , context . State ) ;
74
+ var result = internalResult . Convert ( ) ;
74
75
if ( result . Status == RemoteAuthenticationStatus . Success )
75
76
{
76
77
UpdateUser ( GetUser ( ) ) ;
@@ -84,7 +85,8 @@ public virtual async Task<RemoteAuthenticationResult<TRemoteAuthenticationState>
84
85
RemoteAuthenticationContext < TRemoteAuthenticationState > context )
85
86
{
86
87
await EnsureAuthService ( ) ;
87
- var result = await _jsRuntime . InvokeAsync < RemoteAuthenticationResult < TRemoteAuthenticationState > > ( "AuthenticationService.completeSignIn" , context . Url ) ;
88
+ var internalResult = await _jsRuntime . InvokeAsync < InternalRemoteAuthenticationResult < TRemoteAuthenticationState > > ( "AuthenticationService.completeSignIn" , context . Url ) ;
89
+ var result = internalResult . Convert ( ) ;
88
90
if ( result . Status == RemoteAuthenticationStatus . Success )
89
91
{
90
92
UpdateUser ( GetUser ( ) ) ;
@@ -98,7 +100,8 @@ public virtual async Task<RemoteAuthenticationResult<TRemoteAuthenticationState>
98
100
RemoteAuthenticationContext < TRemoteAuthenticationState > context )
99
101
{
100
102
await EnsureAuthService ( ) ;
101
- var result = await _jsRuntime . InvokeAsync < RemoteAuthenticationResult < TRemoteAuthenticationState > > ( "AuthenticationService.signOut" , context . State ) ;
103
+ var internalResult = await _jsRuntime . InvokeAsync < InternalRemoteAuthenticationResult < TRemoteAuthenticationState > > ( "AuthenticationService.signOut" , context . State ) ;
104
+ var result = internalResult . Convert ( ) ;
102
105
if ( result . Status == RemoteAuthenticationStatus . Success )
103
106
{
104
107
UpdateUser ( GetUser ( ) ) ;
@@ -112,7 +115,8 @@ public virtual async Task<RemoteAuthenticationResult<TRemoteAuthenticationState>
112
115
RemoteAuthenticationContext < TRemoteAuthenticationState > context )
113
116
{
114
117
await EnsureAuthService ( ) ;
115
- var result = await _jsRuntime . InvokeAsync < RemoteAuthenticationResult < TRemoteAuthenticationState > > ( "AuthenticationService.completeSignOut" , context . Url ) ;
118
+ var internalResult = await _jsRuntime . InvokeAsync < InternalRemoteAuthenticationResult < TRemoteAuthenticationState > > ( "AuthenticationService.completeSignOut" , context . Url ) ;
119
+ var result = internalResult . Convert ( ) ;
116
120
if ( result . Status == RemoteAuthenticationStatus . Success )
117
121
{
118
122
UpdateUser ( GetUser ( ) ) ;
@@ -127,13 +131,18 @@ public virtual async ValueTask<AccessTokenResult> RequestAccessToken()
127
131
await EnsureAuthService ( ) ;
128
132
var result = await _jsRuntime . InvokeAsync < InternalAccessTokenResult > ( "AuthenticationService.getAccessToken" ) ;
129
133
130
- if ( string . Equals ( result . Status , AccessTokenResultStatus . RequiresRedirect , StringComparison . OrdinalIgnoreCase ) )
134
+ if ( ! Enum . TryParse < AccessTokenResultStatus > ( result . Status , ignoreCase : true , out var parsedStatus ) )
135
+ {
136
+ throw new InvalidOperationException ( $ "Invalid access token result status '{ result . Status ?? "(null)" } '") ;
137
+ }
138
+
139
+ if ( parsedStatus == AccessTokenResultStatus . RequiresRedirect )
131
140
{
132
141
var redirectUrl = GetRedirectUrl ( null ) ;
133
142
result . RedirectUrl = redirectUrl . ToString ( ) ;
134
143
}
135
144
136
- return new AccessTokenResult ( result . Status , result . Token , result . RedirectUrl ) ;
145
+ return new AccessTokenResult ( parsedStatus , result . Token , result . RedirectUrl ) ;
137
146
}
138
147
139
148
/// <inheritdoc />
@@ -147,13 +156,18 @@ public virtual async ValueTask<AccessTokenResult> RequestAccessToken(AccessToken
147
156
await EnsureAuthService ( ) ;
148
157
var result = await _jsRuntime . InvokeAsync < InternalAccessTokenResult > ( "AuthenticationService.getAccessToken" , options ) ;
149
158
150
- if ( string . Equals ( result . Status , AccessTokenResultStatus . RequiresRedirect , StringComparison . OrdinalIgnoreCase ) )
159
+ if ( ! Enum . TryParse < AccessTokenResultStatus > ( result . Status , ignoreCase : true , out var parsedStatus ) )
160
+ {
161
+ throw new InvalidOperationException ( $ "Invalid access token result status '{ result . Status ?? "(null)" } '") ;
162
+ }
163
+
164
+ if ( parsedStatus == AccessTokenResultStatus . RequiresRedirect )
151
165
{
152
166
var redirectUrl = GetRedirectUrl ( options . ReturnUrl ) ;
153
167
result . RedirectUrl = redirectUrl . ToString ( ) ;
154
168
}
155
169
156
- return new AccessTokenResult ( result . Status , result . Token , result . RedirectUrl ) ;
170
+ return new AccessTokenResult ( parsedStatus , result . Token , result . RedirectUrl ) ;
157
171
}
158
172
159
173
private Uri GetRedirectUrl ( string customReturnUrl )
@@ -242,4 +256,32 @@ internal struct InternalAccessTokenResult
242
256
public AccessToken Token { get ; set ; }
243
257
public string RedirectUrl { get ; set ; }
244
258
}
259
+
260
+ // Internal for testing purposes
261
+ internal struct InternalRemoteAuthenticationResult < TRemoteAuthenticationState > where TRemoteAuthenticationState : RemoteAuthenticationState
262
+ {
263
+ public string Status { get ; set ; }
264
+
265
+ public string ErrorMessage { get ; set ; }
266
+
267
+ public TRemoteAuthenticationState State { get ; set ; }
268
+
269
+ public RemoteAuthenticationResult < TRemoteAuthenticationState > Convert ( )
270
+ {
271
+ var result = new RemoteAuthenticationResult < TRemoteAuthenticationState > ( ) ;
272
+ result . ErrorMessage = ErrorMessage ;
273
+ result . State = State ;
274
+
275
+ if ( Status != null && Enum . TryParse < RemoteAuthenticationStatus > ( Status , ignoreCase : true , out var status ) )
276
+ {
277
+ result . Status = status ;
278
+ }
279
+ else
280
+ {
281
+ throw new InvalidOperationException ( $ "Can't convert status '${ Status ?? "(null)" } '.") ;
282
+ }
283
+
284
+ return result ;
285
+ }
286
+ }
245
287
}
0 commit comments