forked from abpframework/abp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of https://github.com/volosoft/abp into dev
- Loading branch information
Showing
24 changed files
with
514 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# Blazor UI: Authentication | ||
|
||
TODO | ||
The [application startup template](../../Startup-Templates/Application.md) is properly configured to use OpenId Connect to authenticate the user through the server side login form; | ||
|
||
* When the Blazor application needs to authenticate, it is redirected to the server side. | ||
* Users can enter username & password to login if they already have an account. If not, they can use the register form to create a new user. They can also use forgot password and other features. The server side uses IdentityServer4 to handle the authentication. | ||
* Finally, they are redirected back to the Blazor application to complete the login process. | ||
|
||
This is a typical and recommended approach to implement authentication in Single-Page Applications. The client side configuration is done in the startup template, so you can change it. | ||
|
||
See the [Blazor Security document](https://docs.microsoft.com/en-us/aspnet/core/blazor/security) to understand and customize the authentication process. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Blazor UI: Authorization | ||
|
||
Blazor applications can use the same authorization system and permissions defined in the server side. | ||
|
||
> This document is only for authorizing on the Blazor UI. See the [Server Side Authorization](../../Authorization.md) to learn how to define permissions and control the authorization system. | ||
## Basic Usage | ||
|
||
> ABP Framework is **100% compatible** with the Authorization infrastructure provided by the Blazor. See the [Blazor Security Document](https://docs.microsoft.com/en-us/aspnet/core/blazor/security/) to learn all authorization options. This section **only shows some common scenarios**. | ||
### Authorize Attribute | ||
|
||
`[Authorize]` attribute can be used to show a page only to the authenticated users. | ||
|
||
````csharp | ||
@page "/" | ||
@attribute [Authorize] | ||
|
||
You can only see this if you're signed in. | ||
```` | ||
|
||
The `[Authorize]` attribute also supports role-based or policy-based authorization. For example, you can check permissions defined in the server side: | ||
|
||
````csharp | ||
@page "/" | ||
@attribute [Authorize("MyPermission")] | ||
|
||
You can only see this if you have the necessary permission. | ||
```` | ||
|
||
### AuthorizeView | ||
|
||
`AuthorizeView` component can be used in a page/component to conditionally render a part of the content: | ||
|
||
````html | ||
<AuthorizeView Policy="MyPermission"> | ||
<p>You can only see this if you satisfy the "MyPermission" policy.</p> | ||
</AuthorizeView> | ||
```` | ||
|
||
### IAuthorizationService | ||
|
||
`IAuthorizationService` can be injected and used to programmatically check permissions: | ||
|
||
````csharp | ||
public partial class Index | ||
{ | ||
protected override async Task OnInitializedAsync() | ||
{ | ||
if (await AuthorizationService.IsGrantedAsync("MyPermission")) | ||
{ | ||
//... | ||
} | ||
} | ||
} | ||
```` | ||
|
||
If your component directly or indirectly inherits from the `AbpComponentBase`, `AuthorizationService` becomes pre-injected and ready to use. If not, you can always [inject](../../Dependency-Injection.md) the `IAuthorizationService` yourself. | ||
|
||
`IAuthorizationService` can also be used in the view side where `AuthorizeView` component is not enough. | ||
|
||
There are some useful extension methods for the `IAuthorizationService`: | ||
|
||
* `IsGrantedAsync` simply returns `true` or `false` for the given policy/permission. | ||
* `CheckAsync` checks and throws `AbpAuthorizationException` if given policy/permission hasn't granted. You don't have to handle these kind of exceptions since ABP Framework automatically [handles errors](Error-Handling.md). | ||
* `AuthorizeAsync` returns `AuthorizationResult` as the standard way provided by the ASP.NET Core authorization system. | ||
|
||
> See the [Blazor Security Document](https://docs.microsoft.com/en-us/aspnet/core/blazor/security/) to learn all authorization options | ||
## See Also | ||
|
||
* [Authorization](../../Authorization.md) (server side) | ||
* [Blazor Security](https://docs.microsoft.com/en-us/aspnet/core/blazor/security/) (Microsoft documentation) | ||
* [ICurrentUser Service](CurrentUser.md) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Blazor UI: Current Tenant | ||
|
||
`ICurrentTenant` service can be used to get information about the current tenant in a [multi-tenant](../../Multi-Tenancy.md) application. `ICurrentTenant` defines the following properties; | ||
|
||
* `Id` (`Guid`): Id of the current tenant. Can be `null` if the current user is a host user or the tenant could not be determined. | ||
* `Name` (`string`): Name of the current tenant. Can be `null` if the current user is a host user or the tenant could not be determined. | ||
* `IsAvailable` (`bool`): Returns `true` if the `Id` is not `null`. | ||
|
||
**Example: Show the current tenant name on a page** | ||
|
||
````csharp | ||
@page "/" | ||
@using Volo.Abp.MultiTenancy | ||
@inject ICurrentTenant CurrentTenant | ||
@if (CurrentTenant.IsAvailable) | ||
{ | ||
<p>Current tenant name: @CurrentTenant.Name</p> | ||
} | ||
```` | ||
|
||
## See Also | ||
|
||
* [Multi-Tenancy](../../Multi-Tenancy.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Blazor UI: Current User | ||
|
||
`ICurrentUser` service is used to obtain information about the currently authenticated user. Inject the `ICurrentUser` into any component/page and use its properties and methods. | ||
|
||
**Example: Show username & email on a page** | ||
|
||
````csharp | ||
@page "/" | ||
@using Volo.Abp.Users | ||
@inject ICurrentUser CurrentUser | ||
@if (CurrentUser.IsAuthenticated) | ||
{ | ||
<p>Welcome @CurrentUser.UserName</p> | ||
} | ||
```` | ||
|
||
> If you (directly or indirectly) derived your component from the `AbpComponentBase`, you can directly use the base `CurrentUser` property. | ||
`ICurrentUser` provides `Id`, `Name`, `SurName`, `Email`, `Roles` and some other properties. | ||
|
||
> See the [Server Side Current User](../../CurrentUser) service for more information. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Blazor UI: Error Handling | ||
|
||
Blazor, by default, shows a yellow line at the bottom of the page if any unhandled exception occurs. However, this is not useful in a real application. | ||
|
||
ABP provides an automatic error handling system for the Blazor UI. | ||
|
||
* Handles all unhandled exceptions and shows nice and useful messages to the user. | ||
* It distinguishes different kind of exceptions. Hides internal/technical error details from the user (shows a generic error message in these cases). | ||
* It is well integrated to the [server side exception handling](../../Exception-Handling.md) system. | ||
|
||
## Basic Usage | ||
|
||
There are different type of `Exception` classes handled differently by the ABP Framework. | ||
|
||
### UserFriendlyException | ||
|
||
`UserFriendlyException` is a special type of exception. You can directly show a error message dialog to the user by throwing such an exception. | ||
|
||
**Example** | ||
|
||
````csharp | ||
@page "/" | ||
@using Volo.Abp | ||
|
||
<Button Clicked="TestException">Throw test exception</Button> | ||
|
||
@code | ||
{ | ||
private void TestException() | ||
{ | ||
throw new UserFriendlyException("A user friendly error message!"); | ||
} | ||
} | ||
```` | ||
|
||
ABP automatically handle the exception and show an error message to the user: | ||
|
||
![blazor-user-friendly-exception](../../images/blazor-user-friendly-exception.png) | ||
|
||
> You can derive from `UserFriendlyException` or directly implement `IUserFriendlyException` interface to create your own `Exception` class if you need. | ||
|
||
> You can use the [localization system](Localization.md) to show localized error messages. | ||
|
||
### BusinessException and Other Exception Types | ||
|
||
See the [exception handling document](../../Exception-Handling.md) to understand different kind of Exception class and interfaces and other capabilities of the Exception Handling system. | ||
|
||
## Generic Errors | ||
|
||
If the thrown `Exception` is not a special type, it is considered as generic error and a generic error message is shown to the user: | ||
|
||
![blazor-generic-exception-message](../../images/blazor-generic-exception-message.png) | ||
|
||
> All error details (including stack trace) are still written in the browser's console. | ||
|
||
## Server Side Errors | ||
|
||
Errors (like Validation, Authorization and User Friendly Errors) sent by the server are processed as you expect and properly shown to the user. So, error handling system works end to end without need to manually handle exceptions or manually transfer server-to-client error messages. | ||
|
||
## See Also | ||
|
||
* [Exception Handling System](../../Exception-Handling.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Blazor UI: Page Header | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Blazor UI: Routing | ||
|
||
Blazor has its own [routing system](https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing) and you can use it in your applications. ABP doesn't add any new feature to it, except one small improvement for the [modular development](../../Module-Development-Basics.md). | ||
|
||
## AbpRouterOptions | ||
|
||
Blazor `Router` component requires to define `AdditionalAssemblies` when you have components in assemblies/projects other than the main application's entrance assembly. So, if you want to create razor class libraries as ABP modules, you typically want to add the module's assembly to the `AdditionalAssemblies`. In this case, you need to add your module's assembly to the `AbpRouterOptions`. | ||
|
||
**Example** | ||
|
||
````csharp | ||
Configure<AbpRouterOptions>(options => | ||
{ | ||
options.AdditionalAssemblies.Add(typeof(MyBlazorModule).Assembly); | ||
}); | ||
```` | ||
|
||
Write this code in the `ConfigureServices` method of your [module](../../Module-Development-Basics.md). | ||
|
||
`AbpRouterOptions` has another property, `AppAssembly`, which should be the entrance assembly of the application and typically set in the final application's module. If you've created your solution with the [application startup template](../../Startup-Templates/Application.md), it is already configured for you. | ||
|
||
## See Also | ||
|
||
* [Blazor Routing](https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing) (Microsoft Documentation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.