feat: openid login
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
)
|
||||
|
||||
// JWTAuth 由服务配置初始化的 access / refresh 两套 JWT。
|
||||
type JWTAuth struct {
|
||||
Access *utils.JWT
|
||||
Refresh *utils.JWT
|
||||
}
|
||||
|
||||
func LoadJWTAuth() (*JWTAuth, error) {
|
||||
issuer := utils.GetConfigString("jwt.issuer")
|
||||
if issuer == utils.StringEmpty {
|
||||
issuer = "lone-user"
|
||||
}
|
||||
|
||||
access, err := utils.NewJWT(
|
||||
utils.GetConfigString("jwt.access_secret"),
|
||||
issuer,
|
||||
utils.GetConfigInt("jwt.access_ttl"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("jwt access: %w", err)
|
||||
}
|
||||
|
||||
refresh, err := utils.NewJWT(
|
||||
utils.GetConfigString("jwt.refresh_secret"),
|
||||
issuer,
|
||||
utils.GetConfigInt("jwt.refresh_ttl"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("jwt refresh: %w", err)
|
||||
}
|
||||
|
||||
return &JWTAuth{
|
||||
Access: access,
|
||||
Refresh: refresh,
|
||||
}, nil
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/wechat/auth"
|
||||
)
|
||||
|
||||
func NewWechatClient(clientCode string) (*auth.Client, error) {
|
||||
prefix := "wechat." + clientCode
|
||||
appID := utils.GetConfigString(prefix + ".app_id")
|
||||
secret := utils.GetConfigString(prefix + ".app_secret")
|
||||
if appID == utils.StringEmpty || secret == utils.StringEmpty {
|
||||
return nil, fmt.Errorf("wechat config missing for client %s", clientCode)
|
||||
}
|
||||
return auth.NewClient(appID, secret), nil
|
||||
}
|
||||
Reference in New Issue
Block a user