Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/antelcat/server
- Owner: Antelcat
- License: mit
- Created: 2023-05-19T17:04:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-11T13:32:12.000Z (4 months ago)
- Last Synced: 2024-08-11T14:44:39.136Z (4 months ago)
- Topics: authentication, autowired, dependency-injection, jwt, logging, webapi
- Language: C#
- Homepage:
- Size: 881 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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();
}
}
```