Go の http.Handler に組み込める OpenID Connect Provider。
net/http、chi、gin、お好みのルーターで動作。PAR · JAR · DPoP · mTLS · PKCE 内蔵。FAPI 2.0 Baseline / Message Signing をターゲット。
FAPI 2.0 BASELINE · OFCS 138 / 0 · APACHE-2.0 · GO ≥ 1.21
op.New(...) が http.Handler を返す — net/http、chi、ginPROFILEop.WithProfile(profile.FAPI2Baseline) — PAR · JAR · DPoP を一括有効化STORAGEStore インターフェースで持ち込み — inmem · sql · redis · compositeTOKENS自動ローテーション、再利用検知、offline_access の TTL 分離CONFORMANCEOFCS 138 PASSED · 0 FAILED · 3 プランSPAヘッドレス interaction で React からログインを駆動このライブラリでよく作られる構成を 5 つ。それぞれ動作する例があります。
package main
import (
"log"
"net/http"
"github.com/libraz/go-oidc-provider/op"
"github.com/libraz/go-oidc-provider/op/storeadapter/inmem"
)
func main() {
handler, err := op.New(
op.WithIssuer("https://op.example.com"),
op.WithStore(inmem.New()),
op.WithKeyset(myKeyset), // クイックスタート: 揮発鍵の生成例あり
op.WithCookieKey(cookieKey), // 32 バイト — AES-256-GCM
)
if err != nil {
log.Fatal(err)
}
log.Fatal(http.ListenAndServe(":8080", handler))
}
examples/01-minimalと クイックスタート を参照。
handler, _ := op.New(
op.WithIssuer("https://op.example.com"),
op.WithStore(inmem.New()),
op.WithKeyset(myKeyset),
op.WithCookieKey(cookieKey),
op.WithProfile(profile.FAPI2Baseline), // PAR + JAR + DPoP、ES256、alg ロック
op.WithStaticClients(/* JWKS 付き private_key_jwt クライアント */),
)プロファイル 1 行で済む理由
op.WithProfile(profile.FAPI2Baseline) だけで、必要な feature(PAR、JAR、DPoP)の有効化、token_endpoint_auth_methods_supported の FAPI allow-list との絞り込み、discovery の引き締めまでまとめて行います。詳細は ユースケース: FAPI 2.0 Baseline。
handler, _ := op.New(
op.WithIssuer("https://op.example.com"),
op.WithStore(inmem.New()),
op.WithKeyset(myKeyset),
op.WithCookieKey(cookieKey),
op.WithGrants(grant.ClientCredentials, grant.AuthorizationCode, grant.RefreshToken),
)
examples/05-client-credentialsと ユースケース: client_credentials を参照。
handler, _ := op.New(
/* 必須オプション */
op.WithSPAUI(op.SPAUI{ /* SPA エンドポイント */ }),
op.WithCORSOrigins("https://app.example.com"),
)import (
"context"
"github.com/libraz/go-oidc-provider/op/storeadapter/composite"
oidcredis "github.com/libraz/go-oidc-provider/op/storeadapter/redis"
oidcsql "github.com/libraz/go-oidc-provider/op/storeadapter/sql"
)
durable, _ := oidcsql.New(db, oidcsql.MySQL())
volatile, _ := oidcredis.New(context.Background(),
oidcredis.WithDSN("rediss://redis:6380/0"),
oidcredis.WithRedisAuth(redisUser, redisPassword),
)
combined, _ := composite.New(
composite.WithDefault(durable),
composite.With(composite.Sessions, volatile),
composite.With(composite.Interactions, volatile),
composite.With(composite.ConsumedJTIs, volatile),
)
handler, _ := op.New(
op.WithStore(combined),
/* … */
)go get github.com/libraz/go-oidc-provider/op@latestPre-v1.0
本ライブラリは pre-v1.0 です。v1.0.0 までは minor リリースに破壊的変更が入る可能性があります。v1.0 以降は SemVer の厳格運用に切り替わります。詳細は README の status 注記 を参照してください。
Apache-2.0。ソースは libraz/go-oidc-provider。脆弱性報告は SECURITY.md を参照してください。