Fixed visual separation issues

This commit is contained in:
2024-11-21 17:02:15 +01:00
parent 01cd0e1590
commit e8c61dbc7f
4 changed files with 11 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
# HopFrame Authentication # HopFrame Authentication
With the provided HopFrame services, you can secure your endpoints and blazor pages so that only logged-in users or users with the right permissions can access the endpoint/page With the provided HopFrame services, you can secure your endpoints and blazor pages so that only logged-in users or users with the right permissions can access the endpoint/page.
## Usage ## Usage
### Secure your endpoints ### Secure your endpoints
@@ -12,13 +12,17 @@ You can secure your endpoints by adding the `Authorized` attribute.
public ActionResult<string> HelloWorld() { public ActionResult<string> HelloWorld() {
return "Hello, World!"; return "Hello, World!";
} }
```
```csharp
// Only logged-in users can access this endpoint // Only logged-in users can access this endpoint
[HttpGet("hello"), Authorized] [HttpGet("hello"), Authorized]
public ActionResult<string> HelloWorld() { public ActionResult<string> HelloWorld() {
return "Hello, World!"; return "Hello, World!";
} }
```
```csharp
// Only logged-in users with the specified permissions can access this endpoint // Only logged-in users with the specified permissions can access this endpoint
[HttpGet("hello"), Authorized("test.permission", "test.permission.another")] [HttpGet("hello"), Authorized("test.permission", "test.permission.another")]
public ActionResult<string> HelloWorld() { public ActionResult<string> HelloWorld() {
@@ -31,12 +35,14 @@ You can secure your Blazor pages by using the `AuthorizedView` component.
Everything placed inside this component will only be displayed if the authorization was successful. Everything placed inside this component will only be displayed if the authorization was successful.
You can also redirect the user if the authorization fails by specifying a `RedirectIfUnauthorized` url. You can also redirect the user if the authorization fails by specifying a `RedirectIfUnauthorized` url.
```htmlinblazor ```html
<!-- You can either specify one 'Permission', multiple 'Permissions' or none if the user only needs to be logged-in --> <!-- You can either specify one 'Permission', multiple 'Permissions' or none if the user only needs to be logged-in -->
<AuthorizedView Permission="test.permission"> <AuthorizedView Permission="test.permission">
<p>This paragraph is only visible if the user is logged-in and has the required permission</p> <p>This paragraph is only visible if the user is logged-in and has the required permission</p>
</AuthorizedView> </AuthorizedView>
```
```html
<!-- This component will redirect the user to the login page if the user is unauthorized --> <!-- This component will redirect the user to the login page if the user is unauthorized -->
<AuthorizedView RedirectIfUnauthorized="/login" /> <AuthorizedView RedirectIfUnauthorized="/login" />
``` ```

View File

@@ -8,7 +8,6 @@ This Installation adds all HopFrame [pages](../pages) and [services](../services
``` ```
2. Create a [DbContext](./Database.md) that inherits the ``HopDbContext`` and add a data source 2. Create a [DbContext](./Database.md) that inherits the ``HopDbContext`` and add a data source
<p>&nbsp;</p>
3. Add the HopFrame services to your application, provide the previously created `DatabaseContext` that inherits from `HopDbContextBase` 3. Add the HopFrame services to your application, provide the previously created `DatabaseContext` that inherits from `HopDbContextBase`

View File

@@ -1,9 +1,10 @@
# Database initialization # Database initialization
You also need to initialize the data source with the tables from HopFrame You also need to initialize the data source with the tables from HopFrame.
## Create a DbContext ## Create a DbContext
1. Create a c# class that inherits from the `HopDbContextBase` and add a data source (In the example Sqlite is used) 1. Create a c# class that inherits from the `HopDbContextBase` and add a data source (In the example Sqlite is used)\
**IMPORTANT:** You need to leave the `base.OnConfiguring(optionsBuilder)` in place so the HopFrame model relations are set correctly.
```csharp ```csharp
public class DatabaseContext : HopDbContextBase { public class DatabaseContext : HopDbContextBase {
@@ -15,9 +16,6 @@ You also need to initialize the data source with the tables from HopFrame
} }
``` ```
**IMPORTANT:** You need to leave the `base.OnConfiguring(optionsBuilder)` in place so the HopFrame model relations are set correctly.
<p>&nbsp;</p>
2. Register the `DatabaseContext` as a service 2. Register the `DatabaseContext` as a service
```csharp ```csharp

View File

@@ -8,7 +8,6 @@ This Installation adds all HopFrame [endpoints](../endpoints) and [services](../
``` ```
2. Create a [DbContext](./Database.md) that inherits the ``HopDbContext`` and add a data source 2. Create a [DbContext](./Database.md) that inherits the ``HopDbContext`` and add a data source
<p>&nbsp;</p>
3. Add the HopFrame services to your application, provide the previously created `DatabaseContext` that inherits from `HopDbContextBase` 3. Add the HopFrame services to your application, provide the previously created `DatabaseContext` that inherits from `HopDbContextBase`