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
public class ProductRepository : IProductRepository | |
{ | |
private readonly DatabaseContext _context; | |
public ProductRepository(DatabaseContext context) | |
{ | |
_context = context; | |
} | |
public async Task<ProductModel> Get(int tenantId) |
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
[ApiController] | |
public class AdminProductController : ControllerBase | |
{ | |
[HttpPost("product/{Id}")] | |
[Authorize("admin")] | |
public ActionResult Post(AddProductRequestDto addProductRequest) | |
{ | |
// Add some product | |
} | |
} |
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
public class HasScopeHandler : AuthorizationHandler<HasScopeRequirement> | |
{ | |
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context, HasScopeRequirement requirement) | |
{ | |
// If user does not have the scope claim, get out of here | |
if (!context.User.HasClaim(c => c.Type == "scope" && c.Issuer == requirement.Issuer)) | |
return Task.CompletedTask; | |
// Split the scopes string into an array | |
var scopes = context.User.FindFirst(c => c.Type == "scope" && c.Issuer == requirement.Issuer).Value.Split(' '); |
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
public class HasScopeRequirement : IAuthorizationRequirement | |
{ | |
public string Issuer { get; } | |
public string Scope { get; } | |
public HasScopeRequirement(string scope, string issuer) | |
{ | |
Scope = scope ?? throw new ArgumentNullException(nameof(scope)); | |
Issuer = issuer ?? throw new ArgumentNullException(nameof(issuer)); | |
} |
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
/** | |
* Handler that will be called during the execution of a PostLogin flow. | |
* | |
* @param {Event} event - Details about the user and the context in which they are logging in. | |
* @param {PostLoginAPI} api - Interface whose methods can be used to change the behavior of the login. | |
*/ | |
exports.onExecutePostLogin = async (event, api) => { | |
const redirectURI = event.request.query.redirect_uri; | |
const appMetadata = event.user.app_metadata; | |
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
[ApiController] | |
public class ProductController : ControllerBase | |
{ | |
[HttpGet("product/{Id}")] | |
[Authorize] | |
public ActionResult Get(int Id) | |
{ | |
// Get some product by ID | |
} | |
} |
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
public class Startup | |
{ | |
public IConfiguration Configuration { get; } | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public void ConfigureServices(IServiceCollection services) |
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
CREATE TABLE tenant ( | |
id INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
name CHARACTER VARYING NOT NULL UNIQUE, | |
created_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW(), | |
last_modified_at TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW() | |
); | |
CREATE TABLE product ( | |
id INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | |
name CHARACTER VARYING NOT NULL, |
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
from sqlalchemy import Column, Integer, String, select | |
from sqlalchemy.orm import sessionmaker | |
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession | |
import asyncio | |
# Create database schema | |
Base = declarative_base() | |
class Task(Base): | |
__tablename__ = "task" |
NewerOlder