Documentation
¶
Index ¶
- func DecryptAesEcbBase64(data, key string) ([]byte, error)
- func EncryptAesEcbBase64(data []byte, key string) (string, error)
- func MD5(src string) string
- func RandMd5() string
- func RandToken() string
- type App
- type AppCreateParam
- type AppDeleteParam
- type AppUpdateParam
- type Auth
- func (auth *Auth) CheckCaptcha(username, captcha string) error
- func (auth *Auth) CheckUserExist(username string) bool
- func (auth *Auth) GetUser(r *http.Request) (*AuthUser, error)
- func (auth *Auth) Login(w http.ResponseWriter, r *http.Request, username string, remember bool) string
- func (auth *Auth) Logout(w http.ResponseWriter, r *http.Request)
- func (auth *Auth) Register(username, password string) error
- func (auth *Auth) ResetPassword(username, password string) error
- func (auth *Auth) SendCaptcha(username, subject, template string) error
- type AuthUser
- type Authorization
- type AuthorizationDeleteParam
- type Config
- type DB
- type Kerberos
- type KerberosAuthResult
- type KerberosGrantResult
- type Logger
- type Mail
- type Oidc
- func (oidc *Oidc) AddKeyPair(keyID, publicKey, privateKey string)
- func (oidc *Oidc) Auth(user *AuthUser, responseType, clientID, redirectURI, scope, state string) (*OidcCode, error)
- func (oidc *Oidc) CheckClient(appID, secret string) bool
- func (oidc *Oidc) FindClient(clientID string) (*OidcClient, bool)
- func (oidc *Oidc) FindUser(token string) (*OidcUser, error)
- func (oidc *Oidc) GetKeys() *Oidc
- func (oidc *Oidc) GrantToken(code string) (*OidcToken, error)
- func (oidc *Oidc) RefreshToken(token string) (*OidcToken, error)
- type OidcClient
- type OidcCode
- type OidcToken
- type OidcUser
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecryptAesEcbBase64 ¶
DecryptAesEcbBase64 DecryptAesEcbBase64 decode data with base64 and decrypt with key using AES-ECB.
The key should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256
func EncryptAesEcbBase64 ¶
EncryptAesEcbBase64 EncryptAesEcbBase64 encrypt data with key using AES-ECB and encode with base64.
The key should be the AES key, either 16, 24, or 32 bytes to select AES-128, AES-192, or AES-256
Types ¶
type AppCreateParam ¶
type AppDeleteParam ¶
type AppDeleteParam struct {
AppID string `json:"app_id"`
}
type AppUpdateParam ¶
type Auth ¶
type Auth struct {
// contains filtered or unexported fields
}
Auth a http auth service
Http Auth Type - With Cookie (session key) - With Bearer Token (session key) - with Bearer Token (jwt token)
func (*Auth) CheckCaptcha ¶
CheckCaptcha check captcha is valid
func (*Auth) CheckUserExist ¶
CheckUserExist CheckUserExist check the username has been register.
func (*Auth) Login ¶
func (auth *Auth) Login( w http.ResponseWriter, r *http.Request, username string, remember bool, ) string
Login just login with username
No need to check password here
func (*Auth) Logout ¶
func (auth *Auth) Logout(w http.ResponseWriter, r *http.Request)
Logout logout all ticket
func (*Auth) ResetPassword ¶
ResetPassword reset user password
func (*Auth) SendCaptcha ¶
SendCaptcha cache captcha and send
type AuthUser ¶
type AuthUser struct { ID int64 `json:"id"` Username string `json:"username"` LastLogin string `json:"last_login"` }
AuthUser authed user entity
type Authorization ¶
type AuthorizationDeleteParam ¶
type AuthorizationDeleteParam struct {
ID string `json:"id"`
}
type DB ¶
type DB interface { BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }
DB The sql database interface
type Kerberos ¶
type Kerberos struct {
// contains filtered or unexported fields
}
Kerberos Kerberos is a service implement kerberos protocal.
As an example, this project has using kerberos for user login.
func NewKerberos ¶
NewKerberos NewKerberos create a Kerberos service with settings.
func (*Kerberos) Auth ¶
func (k *Kerberos) Auth(username string) (*KerberosAuthResult, error)
Auth Auth implement the process of kerberos auth.
type KerberosAuthResult ¶
KerberosAuthResult KerberosAuthResult is the result of kerberos auth.
type KerberosGrantResult ¶
KerberosGrantResult KerberosGrantResult is the result of kerberos grant.
type Logger ¶
type Logger interface { Fatal(v ...interface{}) Fatalf(format string, v ...interface{}) Fatalln(v ...interface{}) Print(v ...interface{}) Printf(format string, v ...interface{}) Println(v ...interface{}) }
Logger The Log interface
type Mail ¶
type Mail struct {
// contains filtered or unexported fields
}
Mail Mail is a mail micro service The mail micro service could be using as a admin mailer, which could send mail to users.
type Oidc ¶
Oidc oidc service
func (*Oidc) AddKeyPair ¶
AddKeyPair add a key pair
func (*Oidc) Auth ¶
func (oidc *Oidc) Auth( user *AuthUser, responseType, clientID, redirectURI, scope, state string, ) (*OidcCode, error)
Auth build a auth code for user on the client
func (*Oidc) CheckClient ¶
CheckClient check the client id and secret match or not
func (*Oidc) FindClient ¶
func (oidc *Oidc) FindClient(clientID string) (*OidcClient, bool)
FindClient find oidc client by client id
func (*Oidc) GetKeys ¶
GetKeys get the jwks
Here we use Oidc entity for jwks, cause of the property Keys is the only exported one.
func (*Oidc) GrantToken ¶
GrantToken grant the auth code a token
type OidcClient ¶
type OidcClient struct { ClientID string `json:"client_id"` ClientDesc string `json:"client_desc"` RedirectURI string `json:"redirect_uri"` }
OidcClient the oidc client entity
User should register the oidc client first.
The oidc client data saved in db.
type OidcCode ¶
type OidcCode struct { Code string `json:"code"` State string `json:"state"` IDToken string `json:"id_token,omitempty"` AccessToken string `json:"access_token,omitempty"` TokenType string `json:"token_type,omitempty"` ExpiresIn int `json:"expires_in"` RefreshToken string `json:"refresh_token"` Openid string `json:"openid,omitempty"` }
OidcCode oidc code entity
type OidcToken ¶
type OidcToken struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` ExpiresIn int `json:"expires_in"` RefreshToken string `json:"refresh_token"` Openid string `json:"openid"` }
OidcToken oidc token entity