diff --git a/docs/src/04.use-cases.md b/docs/src/04.use-cases.md index e6966ef..ba91e71 100644 --- a/docs/src/04.use-cases.md +++ b/docs/src/04.use-cases.md @@ -2,4 +2,11 @@ Depending on your current render mode, Blazor.Auth will behave differently. In-depth use case diagrams are organized according to different Blazor interactivity types: -- [Interactive WebAssembly](04.use-cases/01.interactive-webassembly.md) \ No newline at end of file +- [Interactive WebAssembly](04.use-cases/01.interactive-webassembly.md) +- ⚠️ [Interactive Server (Work in progress)](04.use-cases/02.interactive-server.md) ⚠️ + +### Refresh Token + +On every `GetAuthenticationStateAsync` call to `AuthenticationStateProvider`, it will check if the current access token is expired. If it is, the user's JWT Pair will automatically be refreshed. + +For a more in-depth overview of this process, refer to the [Architecture](05.architecture.md) section. \ No newline at end of file diff --git a/docs/src/04.use-cases/01.interactive-webassembly.md b/docs/src/04.use-cases/01.interactive-webassembly.md index c56663a..938a8fe 100644 --- a/docs/src/04.use-cases/01.interactive-webassembly.md +++ b/docs/src/04.use-cases/01.interactive-webassembly.md @@ -11,18 +11,27 @@ sequenceDiagram actor user as User participant page as SignIn Page -participant userService as IUserService -participant authService as IAuthenticationService +participant userServiceClient as IUserService (Client) +participant userServiceServer as IUserService (Server) +participant authService as IAuthenticationService (Server) user ->>+ page: Submit Sign-In Form -page ->>+ userService: SignInAsync(signInPayload) -userService ->>+ authService: SignInAsync(signInPayload) -authService ->> authService: Your sign-in logic -authService -->>- userService: AuthenticationResult -userService ->> userService: Update Browser Cookies -userService -->>- page: AuthenticationResult +page ->>+ userServiceClient: SignInAsync(signInPayload) +note over page,userServiceClient: Resolve IUserService from DI
and call it's `SignInAsync` method. +userServiceClient ->>+ userServiceServer: SignInAsync(signInPayload) +note over userServiceClient,userServiceServer: Client-side implementation
will make an HTTP request to the server,
no manual action is required. + +userServiceServer ->>+ authService: SignInAsync(signInPayload) +authService ->> authService: Your server-side sign-in logic + +authService -->>- userServiceServer: AuthenticationResult +userServiceServer ->> userServiceClient: AuthenticationResult +note over userServiceServer,userServiceClient: Server-side implementation will
return AuthenticationResult to the client,
updated cookies will be attached
to the HTTP response
and automalically stored
in the user's browser. + +userServiceClient -->>- page: AuthenticationResult page -->>- user: Redirect to home page -note over user,userService: Upon receiving AuthenticationResult from IUserService,
do a page refresh in order to refresh the User's AuthenticationState

Example: NavigationManager.NavigateTo("/", true) + +note over user,userServiceClient: Upon receiving AuthenticationResult from IUserService,
do a page refresh in order to refresh the User's AuthenticationState

Example: NavigationManager.NavigateTo("/", true). ``` ### Sign-Up @@ -31,40 +40,26 @@ note over user,userService: Upon receiving AuthenticationResult from IUserServic sequenceDiagram actor user as User -participant page as SignIn Page -participant userService as IUserService -participant authService as IAuthenticationService +participant page as SignUp Page +participant userServiceClient as IUserService (Client) +participant userServiceServer as IUserService (Server) +participant authService as IAuthenticationService (Server) user ->>+ page: Submit Sign-Up Form -page ->>+ userService: SignUpAsync(signUpPayload) -userService ->>+ authService: SignUpAsync(signUpPayload) -authService ->> authService: Your sign-up logic -authService -->>- userService: AuthenticationResult -userService ->> userService: Update Browser Cookies -userService -->>- page: AuthenticationResult -page -->- user: Redirect to home page -note over user,userService: Upon receiving AuthenticationResult from IUserService,
do a page refresh in order to refresh the User's AuthenticationState

Example: NavigationManager.NavigateTo("/", true) -``` +page ->>+ userServiceClient: SignUpAsync(signUpPayload) +note over page,userServiceClient: Resolve IUserService from DI
and call it's `SignUpAsync` method. +userServiceClient ->>+ userServiceServer: SignUpAsync(signUpPayload) +note over userServiceClient,userServiceServer: Client-side implementation
will make an HTTP request to the server,
no manual action is required. -### Refresh Token +userServiceServer ->>+ authService: SignUpAsync(signUpPayload) +authService ->> authService: Your server-side sign-up logic -```mermaid -sequenceDiagram +authService -->>- userServiceServer: AuthenticationResult +userServiceServer ->> userServiceClient: AuthenticationResult +note over userServiceServer,userServiceClient: Server-side implementation will
return AuthenticationResult to the client,
updated cookies will be attached
to the HTTP response
and automalically stored
in the user's browser. -actor user as User -participant page as Page -participant lib as Blazor.Auth -participant userService as IUserService -participant authService as IAuthenticationService - -user ->>+ page: Open Page -page ->>+ lib: Get User's AuthenticationState -lib ->>+ userService: If AccessToken expired,\nRefreshJwtPairAsync -userService ->>+ authService: RefreshJwtPairAsync -authService ->> authService: Your refresh logic -authService -->>- userService: AuthenticationResult -userService ->> userService: Update Browser Cookies -userService -->>- lib: AuthenticationResult -lib -->>- page: AuthenticationState -page -->>- user: Display Page +userServiceClient -->>- page: AuthenticationResult +page -->>- user: Redirect to home page + +note over user,userServiceClient: Upon receiving AuthenticationResult from IUserService,
do a page refresh in order to refresh the User's AuthenticationState

Example: NavigationManager.NavigateTo("/", true). ``` \ No newline at end of file diff --git a/docs/src/04.use-cases/02.interactive-server.md b/docs/src/04.use-cases/02.interactive-server.md new file mode 100644 index 0000000..a3cf0cf --- /dev/null +++ b/docs/src/04.use-cases/02.interactive-server.md @@ -0,0 +1,73 @@ +Back to [Use Cases](../04.use-cases.md) + +> ⚠️ +> This section is a work in progress. + +## Interactive Server + +The following sequence diagrams illustrate the use cases for Blazor.Auth in a Blazor application that is currently using interactive WebAssembly render mode: + +### Sign-In + +```mermaid +sequenceDiagram + +actor user as User +participant page as SignIn Page +participant userService as IUserService +participant authService as IAuthenticationService + +user ->>+ page: Submit Sign-In Form +page ->>+ userService: SignInAsync(signInPayload) +userService ->>+ authService: SignInAsync(signInPayload) +authService ->> authService: Your sign-in logic +authService -->>- userService: AuthenticationResult +userService ->> userService: Update Browser Cookies +userService -->>- page: AuthenticationResult +page -->>- user: Redirect to home page +note over user,userService: Upon receiving AuthenticationResult from IUserService,
do a page refresh in order to refresh the User's AuthenticationState

Example: NavigationManager.NavigateTo("/", true) +``` + +### Sign-Up + +```mermaid +sequenceDiagram + +actor user as User +participant page as SignIn Page +participant userService as IUserService +participant authService as IAuthenticationService + +user ->>+ page: Submit Sign-Up Form +page ->>+ userService: SignUpAsync(signUpPayload) +userService ->>+ authService: SignUpAsync(signUpPayload) +authService ->> authService: Your sign-up logic +authService -->>- userService: AuthenticationResult +userService ->> userService: Update Browser Cookies +userService -->>- page: AuthenticationResult +page -->- user: Redirect to home page +note over user,userService: Upon receiving AuthenticationResult from IUserService,
do a page refresh in order to refresh the User's AuthenticationState

Example: NavigationManager.NavigateTo("/", true) +``` + +### Refresh Token + +```mermaid +sequenceDiagram + +actor user as User +participant page as Page +participant lib as Blazor.Auth +participant userService as IUserService +participant authService as IAuthenticationService + +user ->>+ page: Open Page +page ->>+ lib: Get User's AuthenticationState +lib ->>+ userService: If AccessToken expired,\nRefreshJwtPairAsync +userService ->>+ authService: RefreshJwtPairAsync +authService ->> authService: Your refresh logic +authService -->>- userService: AuthenticationResult +userService ->> userService: Update Browser Cookies +userService -->>- lib: AuthenticationResult +lib -->>- page: AuthenticationState +page -->>- user: Display Page +``` \ No newline at end of file diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 74d6012..89f9a71 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -7,4 +7,5 @@ - [Authentication](03.authentication.md) - [Use Cases](04.use-cases.md) - [Interactive WebAssembly](04.use-cases/01.interactive-webassembly.md) + - ⚠️ [Interactive Server (Work in progress)](04.use-cases/02.interactive-server.md) ⚠️ - [Architecture](05.architecture.md)