Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

authentication-authorization-patterns

БесплатноБез исполняемых скриптовНе проверен

Master authentication and authorization patterns including OAuth 2.0, OpenID Connect, JWT tokens, refresh tokens, role-based access control (RBAC)…

thapaliyabikendraот thapaliyabikendra★ 25 звёзд на GitHub

Об этом скилле

Authentication & Authorization Patterns

Master secure authentication and authorization for healthcare applications using OpenIddict, OAuth 2.0, and ABP Framework.

When to Use This Skill

  • Implementing user authentication
  • Setting up OAuth 2.0 / OpenID Connect
  • Managing JWT tokens and refresh tokens
  • Implementing role-based access control (RBAC)
  • Securing API endpoints
  • Handling user permissions
  • Multi-factor authentication (MFA)
  • Single Sign-On (SSO)

Core Concepts

1. Authentication vs Authorization

Authentication: "Who are you?" - Verifying identity Authorization: "What can you do?" - Verifying permissions

// Authentication: User proves identity
[HttpPost("login")]
public async Task<TokenResponse> Login(LoginRequest request)
{
    // Verify credentials
    var user = await _userManager.FindByEmailAsync(request.Email);
    if (user == null || !await _userManager.CheckPasswordAsync(user, request.Password))
    {
        throw new UnauthorizedException("Invalid credentials");
    }

    // User authenticated, generate token
    return await GenerateTokenAsync(user);
}

// Authorization: Check if user has permission
[Authorize(ClinicPermissions.Patients.Create)] // Authorization
public async Task<PatientDto> CreatePatient(CreatePatientDto input)
{
    // User must be authenticated AND have permission
}

2. OAuth 2.0 with OpenIddict

Configure OpenIddict in ABP:

// HttpApi.Host/ClinicHttpApiHostModule.cs
public override void PreConfigureServices(ServiceConfigurationContext context)
{
    var hostingEnvironment = context.Services.GetHostingEnvironment();
    var configuration = context.Services.GetConfiguration();

    PreConfigure<OpenIddictBuilder>(builder =>
    {
        builder.AddValidation(options =>
        {
            options.AddAudiences("Clinic");
            options.UseLocalServer();
            options.UseAspNetCore();
        });
    });

    if (!hostingEnvironment.IsDevelopment())
    {
        PreConfigure<AbpOpenIddictAspNetCoreOptions>(options =>
        {
            options.AddDevelopmentEncryptionAndSigningCertificate = false;
        });

        PreConfigure<OpenIddictServerBuilder>(builder =>
        {
            builder.AddSigningCertificate(
                GetSigningCertificate(hostingEnvironment, configuration));
            builder.AddEncryptionCertificate(
                GetEncryptionCertificate(hostingEnvironment, configuration));
        });
    }
}

OAuth 2.0 Flows:

1. Authorization Code Flow (Most Secure):

// For web applications and mobile apps
// Client redirects to authorization endpoint
// GET /connect/authorize?
//   client_id=clinic-web&
//   redirect_uri=https://clinic.com/callback&
//   response_type=code&
//   scope=openid profile email&
//   state=random_state&
//   code_challenge=hash&
//   code_challenge_method=S256

// After user login, redirected with code
// POST /connect/token
// grant_type=authorization_code&
// code=ABC123&
// redirect_uri=https://clinic.com/callback&
// client_id=clinic-web&
// code_verifier=original_value

2. Client Credentials Flow (Service-to-Service):

// For backend services, no user involved
public class ExternalApiClient
{
    private readonly HttpClient _httpClient;
    private string _accessToken;

    public async Task<string> GetAccessTokenAsync()
    {
        var request = new HttpRequestMessage(HttpMethod.Post, "/connect/token");
        request.Content = new FormUrlEncodedContent(new[]
        {
            new KeyValuePair<string, string>("grant_type", "client_credentials"),
            new KeyValuePair<string, string>("client_id", "reporting-service"),
            new KeyValuePair<string, string>("client_secret", "secret"),
            new KeyValuePair<string, string>("scope", "clinic-api")
        });

        var response = await _httpClient.SendAsync(request);
        var content = await response.Content.ReadFromJsonAsync<TokenResponse>();

        return content.AccessToken;
    }
}

3. Resource Owner Password Credentials (Legacy/Internal):

// Only for trusted first-party applications
// POST /connect/token
// grant_type=password&
// [email protected]&
// password=secretPassword&
// client_id=mobile-app&
// scope=openid profile email offline_access

[HttpPost("token")]
public async Task<IActionResult> Token([FromForm] TokenRequest request)
{
    if (request.GrantType == "password")
    {
        var user = await _userManager.FindByNameAsync(request.Username);
        if (user == null || !await _userManager.CheckPasswordAsync(user, request.Password))
        {
            return BadRequest(new { error = "invalid_grant" });
        }

        return Ok(await CreateTokenResponseAsync(user, request.Scope));
    }

    return BadRequest(new { error = "unsupported_grant_type" });
}

3. JWT Token Structure

JWT Anatomy:

// Header (algorithm and token type)
{
  "alg": "RS256"
Полный SKILL.md на GitHub

Установить authentication-authorization-patterns в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл authentication-authorization-patterns?

Master authentication and authorization patterns including OAuth 2.0, OpenID Connect, JWT tokens, refresh tokens, role-based access control (RBAC), claims-based authorization, and secure token storage for .NET applications with OpenIddict and ABP Framework.

Как установить скилл authentication-authorization-patterns?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл authentication-authorization-patterns запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить authentication-authorization-patterns с