Skip to content

Commit

Permalink
Update use-cases for interactive webassembly
Browse files Browse the repository at this point in the history
  • Loading branch information
ligowsky committed May 30, 2024
1 parent 3a71a18 commit 950ee00
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 41 deletions.
9 changes: 8 additions & 1 deletion docs/src/04.use-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- [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.
75 changes: 35 additions & 40 deletions docs/src/04.use-cases/01.interactive-webassembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/> and call it's `SignInAsync` method.
userServiceClient ->>+ userServiceServer: SignInAsync(signInPayload)
note over userServiceClient,userServiceServer: Client-side implementation <br/> will make an HTTP request to the server, <br/> 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 <br/> return AuthenticationResult to the client, <br/> updated cookies will be attached <br/> to the HTTP response <br/> and automalically stored <br/> in the user's browser.
userServiceClient -->>- page: AuthenticationResult
page -->>- user: Redirect to home page
note over user,userService: Upon receiving AuthenticationResult from IUserService, <br/> do a page refresh in order to refresh the User's AuthenticationState<br/><br/> Example: NavigationManager.NavigateTo("/", true)
note over user,userServiceClient: Upon receiving AuthenticationResult from IUserService, <br/> do a page refresh in order to refresh the User's AuthenticationState<br/><br/> Example: NavigationManager.NavigateTo("/", true).
```

### Sign-Up
Expand All @@ -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, <br/> do a page refresh in order to refresh the User's AuthenticationState<br/><br/> Example: NavigationManager.NavigateTo("/", true)
```
page ->>+ userServiceClient: SignUpAsync(signUpPayload)
note over page,userServiceClient: Resolve IUserService from DI<br/> and call it's `SignUpAsync` method.
userServiceClient ->>+ userServiceServer: SignUpAsync(signUpPayload)
note over userServiceClient,userServiceServer: Client-side implementation <br/> will make an HTTP request to the server, <br/> 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 <br/> return AuthenticationResult to the client, <br/> updated cookies will be attached <br/> to the HTTP response <br/> and automalically stored <br/> 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, <br/> do a page refresh in order to refresh the User's AuthenticationState<br/><br/> Example: NavigationManager.NavigateTo("/", true).
```
73 changes: 73 additions & 0 deletions docs/src/04.use-cases/02.interactive-server.md
Original file line number Diff line number Diff line change
@@ -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, <br/> do a page refresh in order to refresh the User's AuthenticationState<br/><br/> 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, <br/> do a page refresh in order to refresh the User's AuthenticationState<br/><br/> 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
```
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 950ee00

Please sign in to comment.