スキル一覧に戻る
Mcafee123

keycloak-auth

by Mcafee123

0🍴 0📅 2026年1月10日
GitHubで見るManusで実行

SKILL.md


Keycloak Authentication

Configure cookie-based OIDC authentication with Keycloak.

For complete reference, see Library Guide.

Quick Start

appsettings.json

{
  "affolterNET": {
    "Web": {
      "Auth": {
        "Provider": {
          "Authority": "https://keycloak.example.com/realms/myrealm",
          "ClientId": "my-bff-client",
          "ClientSecret": "your-client-secret"
        },
        "CookieAuth": {
          "CookieName": ".MyApp.Auth",
          "ExpireTimeSpan": "01:00:00"
        }
      },
      "BffOptions": {
        "AuthMode": "Authenticate"
      }
    }
  }
}

Authentication Modes

ModeDescription
NoneNo authentication required
AuthenticateValid session required, no permission checks
AuthorizeValid session + Keycloak RPT permissions required

Login/Logout Endpoints

The BFF provides these authentication endpoints:

EndpointMethodDescription
/bff/account/loginGETInitiates OIDC login flow
/bff/account/logoutGET/POSTLogs out user
/bff/account/userGETReturns current user info

Login with Return URL

/bff/account/login?returnUrl=/dashboard

Configuration Options

AuthProviderOptions

PropertyDescription
AuthorityKeycloak realm URL
ClientIdOIDC client identifier
ClientSecretOIDC client secret

CookieAuthOptions

PropertyTypeDefaultDescription
CookieNamestring.AspNetCore.AuthAuthentication cookie name
ExpireTimeSpanTimeSpan01:00:00Cookie expiration
SlidingExpirationbooltrueExtend cookie on activity

Token Refresh

The RefreshTokenMiddleware automatically refreshes tokens:

  • Checks token expiration before each request
  • Refreshes when < 10 seconds until expiration
  • Uses semaphore lock to prevent concurrent refreshes
  • Signs out user on refresh failure

SPA Integration

The BFF returns 401 instead of redirecting to Keycloak:

// Handle 401 in your SPA
if (response.status === 401) {
    window.location.href = '/bff/account/login?returnUrl=' +
        encodeURIComponent(window.location.pathname);
}

Troubleshooting

Login redirects to wrong URL

  • Verify Authority URL is correct
  • Check Keycloak client redirect URIs include your app
  • Ensure cookies are being set (check SameSite settings)

Token refresh fails

  • Check refresh token hasn't expired
  • Verify Keycloak client has offline_access scope
  • Review Keycloak session timeout settings

Logout doesn't work

  • Ensure Keycloak client has logout redirect URI configured
  • Check if front-channel logout is enabled

スコア

総合スコア

50/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

0/10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です