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.WithCookieKeys(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.WithCookieKeys(cookieKey),
op.WithProfile(profile.FAPI2Baseline), // PAR + JAR、DPoP 既定、ES256、FAPI 絞り込み
op.WithStaticClients(/* JWKS 付き private_key_jwt クライアント */),
)プロファイル 1 行で済む理由
op.WithProfile(profile.FAPI2Baseline) だけで、プロファイルが必須とする機能(PAR、JAR)の有効化、token_endpoint_auth_methods_supported の FAPI allow-list への絞り込み、mTLS が明示されていない場合の DPoP 既定選択、discovery の引き締めまでまとめて行います。詳細は ユースケース: FAPI 2.0 Baseline。
handler, _ := op.New(
op.WithIssuer("https://op.example.com"),
op.WithStore(inmem.New()),
op.WithKeyset(myKeyset),
op.WithCookieKeys(cookieKey),
op.WithGrants(grant.ClientCredentials, grant.AuthorizationCode, grant.RefreshToken),
)
examples/05-client-credentialsと ユースケース: client_credentials を参照。
handler, _ := op.New(
/* 必須オプション */
op.WithLoginFlow(flow),
op.WithSPAUI(op.SPAUI{
LoginMount: "/login",
StaticDir: "./web/static",
}),
)UI オプション
op.WithSPAUI / op.WithConsentUI / op.WithChooserUI は、OP が SPA の入口をマウントする構成、独自の同意テンプレート、独自のアカウント選択テンプレートを扱うためのオプションです。SPA の配信を自前の router で持ちたい場合は interaction.JSONDriver も使えます。詳細は examples/10-react-login と ユースケース: SPA を参照してください。
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@v0.9.3Pre-v1.0
本ライブラリは pre-v1.0 です。v1.0.0 までは minor リリースに破壊的変更が入る可能性があります。v1.0 以降は SemVer の厳格運用に切り替わります。詳細は README の status 注記 を参照してください。
Apache-2.0。ソースは libraz/go-oidc-provider。脆弱性報告は SECURITY.md を参照してください。