Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/antelcat/server

Server side of foundation
https://github.com/antelcat/server

authentication autowired dependency-injection jwt logging webapi

Last synced: about 2 months ago
JSON representation

Server side of foundation

Awesome Lists containing this project

README

        

# Antelcat.Foundation.Server

Server side of code foundation

Reference to :

+ [Antelcat.Foundation.Core](https://github.com/Antelcat/Foundation-Core)
+ [Feast.RequestMapper](https://github.com/feast107/RequestMapper)

## Dependency-Injection

## Authentication

+ Jwt

Easily configure jwt authentication by serialize model into claims and back :

``` c#
builder.Services.ConfigureJwt(
configure: static jwt => jwt.Secret = "Your secret key",
validation: static async (identity,context) => {
if (identity.Id < 0) context.Fail("Jwt token invalid");
},
denied: static context => "Your role has no permission",
failed: static context => "You are an unauthorized audience"
);
```

when inherit from [BaseController](/src/Antelcat.Server/Controllers/BaseController.cs), controllers can resolve identity like :

``` c#
[ApiController]
public class IdentityController : BaseController{

[Autowired]
private JwtConfigure configure;

[HttpPost]
[AllowAnonymous]
public IActionResult MyToken([FromBody]IdentityModel identity){
return configure.CreateToken(identity);
}

[HttpGet]
[Authorize]
public IActionResult WhoAmI(){
return base.Identity();
}
}
```

+ Cookie

Cookie authentication seems to be less related to identity model but you still need to provide it :

``` c#
builder.Services.ConfigureCookie(
denied: static context => "Your role has no permission",
failed: static context => "You are an unauthorized audience"
);
```

``` c#
[ApiController]
public class IdentityController : BaseController{

[HttpPost]
[AllowAnonymous]
public async Task SignInAsync([FromBody]IdentityModel identity){
base.SignInAsync(identity, "User");
return "Successfully login";
}

[HttpGet]
[Authorize]
public async Task SignOutAsync(){
await SignOutAsync();
return "Successfully logout";
}

[HttpGet]
[Authorize]
public IActionResult WhoAmI(){
return base.Identity();
}
}
```