server

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const AppIdContextKey = ContextKey("appId")
View Source
const (
	ErrorsNoToken string = "no Token Verifier"
)

Variables

This section is empty.

Functions

func ClientStore

func ClientStore() oauth2.ClientStore

func Init

func Init()

func InitClientStore

func InitClientStore() oauth2.ClientStore

func NewDatabaseClientStore

func NewDatabaseClientStore() (oauth2.ClientStore, error)

NewClientStore create client store *

  • Database Client Store

func ScopeJoin

func ScopeJoin(scope []Scope) string

func ValidationBearerToken

func ValidationBearerToken(c *gin.Context) (oauth2.TokenInfo, error)

Types

type ContextKey

type ContextKey string

type DatabaseClientStore

type DatabaseClientStore struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ClientStore client information store

func (*DatabaseClientStore) GetByID

func (cs *DatabaseClientStore) GetByID(ctx context.Context, id string) (oauth2.ClientInfo, error)

GetByID according to the ID for the client information

type IEmailUserHandler

type IEmailUserHandler interface {
	GetEmailUserDetails(ctx context.Context, email string, code string) (*SecurityModel.UserDetails, error)
}

type IMobileUserHandler

type IMobileUserHandler interface {
	GetMobileUserDetails(ctx context.Context, mobile string, code string) (*SecurityModel.UserDetails, error)
}

type ISocialUserHandler

type ISocialUserHandler interface {
	GetSocialUserDetails(ctx context.Context, social string, code string) (*SecurityModel.UserDetails, error)
}

type IUserHandler

type IUserHandler interface {
	GetUserDetails(ctx context.Context, username string, password string) (*SecurityModel.UserDetails, error)
}

type LoginForm

type LoginForm struct {
	Mode     string `form:"mode" json:"mode"`
	Username string `form:"username" json:"username"`
	Password string `form:"password" json:"password"`
}

type OAuth2Controller

type OAuth2Controller struct {
	controller.ResourceController
	OAuth2Server *OAuth2Server     `inject:"oauth2Server"`
	TokenStore   oauth2.TokenStore `inject:"tokenStore"`
	// contains filtered or unexported fields
}

func (*OAuth2Controller) Auth

func (o *OAuth2Controller) Auth(c *gin.Context)

*

  • GET /auth *
  • OK => auth.html 授权页面

func (*OAuth2Controller) Authorize

func (o *OAuth2Controller) Authorize(c *gin.Context)

*

  • POST /authorize *
  • 授权接口:

func (*OAuth2Controller) GetTokenRedis

func (o *OAuth2Controller) GetTokenRedis(method, code string) (oauth2.TokenInfo, error)

func (*OAuth2Controller) HandleTokenRequest

func (o *OAuth2Controller) HandleTokenRequest(c *gin.Context)

*

  • POST /token *
  • 处理token请求

func (*OAuth2Controller) InitRouter

func (c *OAuth2Controller) InitRouter(g *gin.RouterGroup) *gin.RouterGroup

func (*OAuth2Controller) Login

func (o *OAuth2Controller) Login(c *gin.Context)

*

  • POST /login

func (*OAuth2Controller) QueryToken

func (o *OAuth2Controller) QueryToken(c *gin.Context)

*

  • GET /token *
  • 根据授权码获取已授权的Token

type OAuth2Server

type OAuth2Server struct {
	ClientStore    oauth2.ClientStore    `inject:"clientStore"`
	TokenStore     oauth2.TokenStore     `inject:"tokenStore"`
	AccessGenerate oauth2.AccessGenerate `inject:"accessGenerate"`
	// AuthorizeGenerate oauth2.AuthorizeGenerate `inject:"authorizeGenerate"`
	UserHandler       IUserHandler       `inject:"userHandler"`
	MobileUserHandler IMobileUserHandler `inject:"userHandler"`
	EmailUserHandler  IEmailUserHandler  `inject:"userHandler"`
	SocialUserHandler ISocialUserHandler `inject:"userHandler"`
	// contains filtered or unexported fields
}

func (*OAuth2Server) ClientInfoHandler

func (s *OAuth2Server) ClientInfoHandler(r *http.Request) (string, string, error)

func (*OAuth2Server) GetTokenData

func (s *OAuth2Server) GetTokenData(ti oauth2.TokenInfo) map[string]interface{}

func (*OAuth2Server) HandleAuthorizeRequest

func (s *OAuth2Server) HandleAuthorizeRequest(w http.ResponseWriter, r *http.Request) error

func (*OAuth2Server) HandleTokenRequest

func (s *OAuth2Server) HandleTokenRequest(w http.ResponseWriter, r *http.Request) error

func (*OAuth2Server) ValidationBearerToken

func (s *OAuth2Server) ValidationBearerToken(r *http.Request) (oauth2.TokenInfo, error)

type OAuthClient

type OAuthClient struct {
	ClientId     string    `gorm:"primaryKey"`
	ClientSecret string    ``
	ResourceIds  string    ``
	Scope        string    ``
	CreatedBy    string    `json:"created_by"`
	CreatedTime  time.Time `gorm:"autoCreateTime;type:TIMESTAMP;default:CURRENT_TIMESTAMP;<-:create" json:"created_time"`
	ModifiedBy   string    `json:"modified_by"`
	ModifiedTime time.Time `gorm:"autoUpdateTime;type:TIMESTAMP;default:CURRENT_TIMESTAMP on update current_timestamp" json:"modified_time"`
	DelFlag      bool      `gorm:"default:false" json:"del_flag"`
}

*

  • OAuth2 Client: webapp/1234567890

func (*OAuthClient) GetDomain

func (c *OAuthClient) GetDomain() string

func (*OAuthClient) GetID

func (c *OAuthClient) GetID() string

func (*OAuthClient) GetSecret

func (c *OAuthClient) GetSecret() string

func (*OAuthClient) GetUserID

func (c *OAuthClient) GetUserID() string

func (*OAuthClient) IsPublic

func (c *OAuthClient) IsPublic() bool

func (*OAuthClient) TableName

func (c *OAuthClient) TableName() string

func (*OAuthClient) VerifyPassword

func (c *OAuthClient) VerifyPassword(password string) bool

*

  • OAuth2 校验 ClientSecret 方法
  • TODO: 数据库保存ClientSecret

type Scope

type Scope struct {
	ID    string `yaml:"id"`
	Title string `yaml:"title"`
}

func ScopeFilter

func ScopeFilter(clientID string, scope string) (s []Scope)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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