core

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumResponse

func DumResponse(writer io.Writer, header string, r *http.Response) error

func DumpRequest

func DumpRequest(writer io.Writer, header string, r *http.Request) error

Types

type IDToken

type IDToken struct {
	Issuer           string `json:"iss,omitempty"`
	Sub              string `json:"sub,omitempty"`
	Aud              string `json:"aud,omitempty"`
	Nonce            string `json:"nonce,omitempty"`
	Expire           int64  `json:"exp,omitempty"`
	PreferedUserName string `json:"preferred_username"`
	AccessTokenHash  string `json:"at_hash,omitempty"`
	IssueAt          int64  `json:"iat,omitempty"`
}
{
	"iss": "http://server.example.com",
	"sub": "248289761001",
	"aud": "s6BhdRkqt3",
	"nonce": "n-0S6_WzA2Mj",
	"exp": 1311281970,
	"iat": 1311280970
  }

func (*IDToken) GetClaims

func (idt *IDToken) GetClaims() jwt.MapClaims

type JWKS

type JWKS struct {
	Keys []interface{} `json:"keys"`
}

type JWTKey

type JWTKey struct {
	KeyType string `json:"kty"`
	Use     string `json:"use"`
	Kid     string `json:"kid"`
	//	X5t string `json:"x5t"`
	//	E   string `json:"e"`
	//	N   string `json:"n"`
	//	X5c string `json:"x5c"`
	Alg string `json:"alg"`
}

type Manager

type Manager struct {
	HTTPScheme string

	UserStore       store.UserStore
	PrivateKeyBytes []byte
	Kid             string
	// contains filtered or unexported fields
}

func NewDefaultManager

func NewDefaultManager() *Manager

func NewManager

func NewManager() *Manager

func (*Manager) GenerateAccessToken

func (m *Manager) GenerateAccessToken(ctx context.Context, gt oauth2.GrantType, tgr *oauth2.TokenGenerateRequest) (accessToken oauth2.TokenInfo, err error)

GenerateAccessToken generate the access token

func (*Manager) GenerateAuthToken

func (m *Manager) GenerateAuthToken(ctx context.Context, rt oauth2.ResponseType, tgr *oauth2.TokenGenerateRequest) (authToken oauth2.TokenInfo, err error)

GenerateAuthToken generate the authorization token(code)

func (*Manager) GetClient

func (m *Manager) GetClient(ctx context.Context, clientID string) (cli oauth2.ClientInfo, err error)

func (*Manager) LoadAccessToken

func (m *Manager) LoadAccessToken(ctx context.Context, access string) (oauth2.TokenInfo, error)

according to the access token for corresponding token information

func (*Manager) LoadRefreshToken

func (m *Manager) LoadRefreshToken(ctx context.Context, refresh string) (oauth2.TokenInfo, error)

according to the refresh token for corresponding token information

func (*Manager) MapAccessGenerate

func (m *Manager) MapAccessGenerate(gen oauth2.AccessGenerate)

func (*Manager) RefreshAccessToken

func (m *Manager) RefreshAccessToken(ctx context.Context, tgr *oauth2.TokenGenerateRequest) (accessToken oauth2.TokenInfo, err error)

refreshing an access token

func (*Manager) RemoveAccessToken

func (m *Manager) RemoveAccessToken(ctx context.Context, access string) (err error)

use the access token to delete the token information

func (*Manager) RemoveRefreshToken

func (m *Manager) RemoveRefreshToken(ctx context.Context, refresh string) (err error)

use the refresh token to delete the token information

func (*Manager) SetClientStore

func (m *Manager) SetClientStore(clientStore oauth2.ClientStore)

func (*Manager) SetTokenStore

func (m *Manager) SetTokenStore(tStore oauth2.TokenStore)

type OpenIDConfig

type OpenIDConfig struct {
	Issuer                             string   `json:"issuer"`
	JwksURI                            string   `json:"jwks_uri"`
	AuthorizationEndpoint              string   `json:"authorization_endpoint"`
	TokenEndpoint                      string   `json:"token_endpoint"`
	UserInfoEndpoint                   string   `json:"userinfo_endpoint"`
	EndSessionEndpoint                 string   `json:"end_session_endpoint"`
	CheckSessionIframe                 string   `json:"check_session_iframe"`
	RevocationEndpoint                 string   `json:"revocation_endpoint"`
	IntrospectionEndpoint              string   `json:"introspection_endpoint"`
	DeviceAuthorizationEndpoint        string   `json:"device_authorization_endpoint"`
	FrontchannelLogoutSupported        bool     `json:"frontchannel_logout_supported"`
	FrontchannelLogoutSessionSupported bool     `json:"frontchannel_logout_session_supported"`
	BackchannelLogoutSupported         bool     `json:"backchannel_logout_supported"`
	BackchannelLogoutSessionSupported  bool     `json:"backchannel_logout_session_supported"`
	ScopesSupported                    []string `json:"scopes_supported"`
	ClaimsSupported                    []string `json:"claims_supported"`
	GrantTypesSupported                []string `json:"grant_types_supported"`
	ResponseTypesSupported             []string `json:"response_types_supported"`
	ResponseModesSupported             []string `json:"response_modes_supported"`
	TokenEndpointAuthMethodsSupported  []string `json:"token_endpoint_auth_methods_supported"`
	IDTokenSigningAlgValuesSupported   []string `json:"id_token_signing_alg_values_supported"`
	SubjectTypesSupported              []string `json:"subject_types_supported"`
	CodeChallengeMethodsSupported      []string `json:"code_challenge_methods_supported"`
	RequestParameterSupported          bool     `json:"request_parameter_supported"`
}

type OpenIDExtend

type OpenIDExtend struct {
	PrivateKeyByets []byte
	UserStore       *store.DbUserStore
	ClientStore     *store.ClientStore
}

func NewOpenIDExtend

func NewOpenIDExtend() *OpenIDExtend

func (*OpenIDExtend) PasswordAuthorizationHandler

func (oidext *OpenIDExtend) PasswordAuthorizationHandler(username, password string) (userID string, err error)

func (*OpenIDExtend) UserAuthorizeHandler

func (oidext *OpenIDExtend) UserAuthorizeHandler(w http.ResponseWriter, r *http.Request) (userID string, err error)
func (oidext *OpenIDExtend) ClientScopeHandler(clientid, scope string) (allow bool, err error) {
	scopes := strings.Split(scope, " ")
	supportScopes := oidext.ClientStore.GetClientScopes(clientid)
	for _, s := range scopes {
		isSupport := false
		for _, ss := range supportScopes {
			if strings.EqualFold(s, ss) {
				isSupport = true
				break
			}
		}
		if !isSupport {
			return false, fmt.Errorf("Client:%s Scope:%s not Supported", clientid, s)
		}
	}
	log.Debugf("Validate Client %s Scope:%s", clientid, scope)
	return true, nil
}

type RSAJWTKey

type RSAJWTKey struct {
	JWTKey
	E         string         `json:"e"` //The "e" (exponent) parameter contains the exponent value for the RSA	public key.
	N         string         `json:"n"` //The "n" (modulus) parameter contains the modulus value for the RSA public key.  It is represented as a Base64urlUInt-encoded value.
	PublicKey *rsa.PublicKey `json:"-"`
}

func NewRSAJWTKey

func NewRSAJWTKey(publicKey *rsa.PublicKey) RSAJWTKey

NewRSAJWTKey 新建一个RSAJWTKey

func NewRSAJWTKeyWithPEM

func NewRSAJWTKeyWithPEM(pemBytes []byte) RSAJWTKey

NewRSAJWTKeyWithPEM 通过pem证书文件内容新建一个RSAJWTKey

Jump to

Keyboard shortcuts

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