Help us shape the future of Go! Take the 2026 Go Developer Survey

oidc

package
v0.14.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package oidc 实现 OIDC 单点登录(P2,stdlib-only,无第三方依赖)。

流程(Authorization Code):

  1. GET /api/v1/user/oidc/login → 302 到 IdP 授权页(state 为 HMAC 签名时间戳,防 CSRF)
  2. IdP 回调 GET /api/v1/user/oidc/callback?code&state → 验 state → 换 token → 拉 userinfo
  3. 按 (issuer, sub) 匹配本地用户,其次按 email,未命中且允许注册则建号
  4. 签发本站 JWT,302 回前端 /#/oidc/callback?token=xxx

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled          bool   `mapstructure:"enabled"`
	Issuer           string `mapstructure:"issuer"` // 如 https://idp.example.com/realms/fcb
	ClientID         string `mapstructure:"client_id"`
	ClientSecret     string `mapstructure:"client_secret"`
	Scopes           string `mapstructure:"scopes"`            // 默认 "openid profile email"
	FrontendCallback string `mapstructure:"frontend_callback"` // 默认 /#/oidc/callback
}

Config OIDC 配置(conf.SecurityConfig.OIDC)

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service OIDC 登录服务

func NewService

func NewService(cfg Config) *Service

NewService 构建服务

func (*Service) Enabled

func (s *Service) Enabled() bool

Enabled 是否启用

func (*Service) ExchangeCallback

func (s *Service) ExchangeCallback(ctx context.Context, baseURL, code, state string) (string, error)

ExchangeCallback 处理回调:code → token → userinfo → 本地用户 → JWT

func (*Service) FrontendCallback

func (s *Service) FrontendCallback() string

FrontendCallback 前端回调地址(带 token= 前缀;hash 路由 query)

func (*Service) LoginURL

func (s *Service) LoginURL(ctx context.Context, baseURL string) (string, error)

LoginURL 构建授权跳转地址

func (*Service) RedirectURI

func (s *Service) RedirectURI(baseURL string) string

RedirectURI 回调地址(本站)

func (*Service) TestDiscovery

func (s *Service) TestDiscovery(ctx context.Context) error

TestDiscovery 管理端「测试连接」:验证 issuer 的 discovery 端点可达且合法。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL