[Blazor][Wasm] Add missing state callbacks (#19405)
* Adds missing callback when logging in and logging out successfully
This commit is contained in:
parent
eed3605ae5
commit
2b72b637bf
|
|
@ -74,6 +74,16 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Parameter] public RenderFragment LogOutSucceeded { get; set; } = DefaultLoggedOutFragment;
|
[Parameter] public RenderFragment LogOutSucceeded { get; set; } = DefaultLoggedOutFragment;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets an event callback that will be invoked with the stored authentication state when a log in operation succeeds.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter] public EventCallback<TAuthenticationState> OnLogInSucceeded { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets an event callback that will be invoked with the stored authentication state when a log out operation succeeds.
|
||||||
|
/// </summary>
|
||||||
|
[Parameter] public EventCallback<TAuthenticationState> OnLogOutSucceeded { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the <see cref="IJSRuntime"/> to use for performin JavaScript interop.
|
/// Gets or sets the <see cref="IJSRuntime"/> to use for performin JavaScript interop.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -242,6 +252,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||||
// is when we are doing a redirect sign in flow.
|
// is when we are doing a redirect sign in flow.
|
||||||
throw new InvalidOperationException("Should not redirect.");
|
throw new InvalidOperationException("Should not redirect.");
|
||||||
case RemoteAuthenticationStatus.Success:
|
case RemoteAuthenticationStatus.Success:
|
||||||
|
if (OnLogInSucceeded.HasDelegate)
|
||||||
|
{
|
||||||
|
await OnLogInSucceeded.InvokeAsync(result.State);
|
||||||
|
}
|
||||||
await NavigateToReturnUrl(GetReturnUrl(result.State));
|
await NavigateToReturnUrl(GetReturnUrl(result.State));
|
||||||
break;
|
break;
|
||||||
case RemoteAuthenticationStatus.OperationCompleted:
|
case RemoteAuthenticationStatus.OperationCompleted:
|
||||||
|
|
@ -305,6 +319,10 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||||
// is when we are doing a redirect sign in flow.
|
// is when we are doing a redirect sign in flow.
|
||||||
throw new InvalidOperationException("Should not redirect.");
|
throw new InvalidOperationException("Should not redirect.");
|
||||||
case RemoteAuthenticationStatus.Success:
|
case RemoteAuthenticationStatus.Success:
|
||||||
|
if (OnLogOutSucceeded.HasDelegate)
|
||||||
|
{
|
||||||
|
await OnLogOutSucceeded.InvokeAsync(result.State);
|
||||||
|
}
|
||||||
await NavigateToReturnUrl(GetReturnUrl(result.State, Navigation.ToAbsoluteUri(ApplicationPaths.LogOutSucceededPath).ToString()));
|
await NavigateToReturnUrl(GetReturnUrl(result.State, Navigation.ToAbsoluteUri(ApplicationPaths.LogOutSucceededPath).ToString()));
|
||||||
break;
|
break;
|
||||||
case RemoteAuthenticationStatus.OperationCompleted:
|
case RemoteAuthenticationStatus.OperationCompleted:
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||||
public class RemoteAuthenticatorCoreTests
|
public class RemoteAuthenticatorCoreTests
|
||||||
{
|
{
|
||||||
private const string _action = nameof(RemoteAuthenticatorViewCore<RemoteAuthenticationState>.Action);
|
private const string _action = nameof(RemoteAuthenticatorViewCore<RemoteAuthenticationState>.Action);
|
||||||
|
private const string _onLogInSucceded = nameof(RemoteAuthenticatorViewCore<RemoteAuthenticationState>.OnLogInSucceeded);
|
||||||
|
private const string _onLogOutSucceeded = nameof(RemoteAuthenticatorViewCore<RemoteAuthenticationState>.OnLogOutSucceeded);
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task AuthenticationManager_Throws_ForInvalidAction()
|
public async Task AuthenticationManager_Throws_ForInvalidAction()
|
||||||
|
|
@ -183,9 +185,14 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||||
State = remoteAuthenticator.AuthenticationState
|
State = remoteAuthenticator.AuthenticationState
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var loggingSucceededCalled = false;
|
||||||
|
|
||||||
var parameters = ParameterView.FromDictionary(new Dictionary<string, object>
|
var parameters = ParameterView.FromDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
[_action] = RemoteAuthenticationActions.LogInCallback
|
[_action] = RemoteAuthenticationActions.LogInCallback,
|
||||||
|
[_onLogInSucceded] = new EventCallbackFactory().Create< RemoteAuthenticationState>(
|
||||||
|
remoteAuthenticator,
|
||||||
|
(state) => loggingSucceededCalled = true),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -193,6 +200,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(fetchDataUrl, jsRuntime.LastInvocation.args[0]);
|
Assert.Equal(fetchDataUrl, jsRuntime.LastInvocation.args[0]);
|
||||||
|
Assert.True(loggingSucceededCalled);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -431,9 +439,14 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||||
State = remoteAuthenticator.AuthenticationState
|
State = remoteAuthenticator.AuthenticationState
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var loggingOutSucceededCalled = false;
|
||||||
var parameters = ParameterView.FromDictionary(new Dictionary<string, object>
|
var parameters = ParameterView.FromDictionary(new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
[_action] = RemoteAuthenticationActions.LogOutCallback
|
[_action] = RemoteAuthenticationActions.LogOutCallback,
|
||||||
|
[_onLogOutSucceeded] = new EventCallbackFactory().Create<RemoteAuthenticationState>(
|
||||||
|
remoteAuthenticator,
|
||||||
|
(state) => loggingOutSucceededCalled = true),
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -441,6 +454,7 @@ namespace Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
Assert.Equal(fetchDataUrl, jsRuntime.LastInvocation.args[0]);
|
Assert.Equal(fetchDataUrl, jsRuntime.LastInvocation.args[0]);
|
||||||
|
Assert.True(loggingOutSucceededCalled);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue