1 Star 0 Fork 0

carlmax_my/console-core-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
authing.go 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
carlmax_my 提交于 2024-12-19 15:19 . add general type for api reponse
package authing_v3
import (
"log"
"os"
"gitee.com/carlmax_my/console-core-go/pkg/idp"
"gitee.com/carlmax_my/console-core-go/pkg/util"
"gitee.com/carlmax_my/authing-golang-sdk/v3/management"
)
type AuthingCli struct {
// for global general mgmt
// UserPoolId string
// Secret string
Cli *management.ManagementClient
UserPoolId string
UserPoolSecret string
TenantId *string
AuthingHost string
UseEnvHost bool
// for app
AuthCli *AuthingAuthCli
}
func NewAuthingCli(tenantId *string, useEnvHost bool) *AuthingCli {
userPoolId := os.Getenv("AUTHING_USER_POOL_ID")
secret := os.Getenv("AUTHING_SECRET")
authingHost := os.Getenv("AUTHING_CONSOLE_HOST")
cli := NewAuthingMgmtCli(userPoolId, secret, authingHost, tenantId, useEnvHost)
cli.SetUserPoolId(userPoolId)
appId := os.Getenv("AUTHING_SDP_APP_ID")
appSecret := os.Getenv("AUTHING_SDP_APP_SECRET")
appHost := idp.GetAuthingAppHost(os.Getenv("AUTHING_SDP_APP_IDENTIFIER"))
appRedirectUri := os.Getenv("AUTHING_SDP_APP_REDIRECT_URI")
authingAuthCli := &AuthingAuthCli{
UserPoolId: userPoolId,
AppId: appId,
AppSecret: appSecret,
AppHost: appHost,
}
if appId != "" && !idp.IsAuthingAppDynamicMode() { // single app mode, then we can set app id in env file
authCli := NewAuthingAuthCli(appId, appSecret, appHost, appRedirectUri, "", "")
authingAuthCli.Cli = authCli
}
return &AuthingCli{
Cli: cli,
AuthingHost: authingHost,
UseEnvHost: useEnvHost,
UserPoolId: userPoolId,
UserPoolSecret: secret,
TenantId: tenantId,
AuthCli: authingAuthCli,
}
}
func NewAuthingMgmtCli(userPoolId string, secret string, authingHost string, tenantId *string, useEnvHost bool) *management.ManagementClient {
mgmtOptions := management.ManagementClientOptions{
AccessKeyId: userPoolId, // Authing Access Key ID
AccessKeySecret: secret, // Authing Access Key Secret
// Host: authingHost, // Authing 服务器地址,默认为 https://api.authing.cn
}
if useEnvHost {
mgmtOptions.Host = authingHost
}
if !util.IsStringEmpty(tenantId) {
mgmtOptions.TenantId = *tenantId
}
cli, _ := management.NewManagementClient(&mgmtOptions)
return cli
}
func (a *AuthingCli) ResetCliTenantId(tenantId string) {
a.Cli = NewAuthingMgmtCli(a.UserPoolId, a.UserPoolSecret, a.AuthingHost, &tenantId, a.UseEnvHost)
}
func (a *AuthingCli) ResetAuthCli(appId, appSecret, appHost, appRedirectUri, appLogoutRedirectUri, accessToken string) {
a.AuthCli.ResetAuthCli(appId, appSecret, appHost, appRedirectUri, appLogoutRedirectUri, accessToken)
}
func (a *AuthingCli) GetAppHost() string {
return a.AuthCli.AppHost
}
func (a *AuthingCli) GetAppId() string {
return a.AuthCli.AppId
}
func (a *AuthingCli) PrintOptions() {
log.Println("a.UserPoolId", a.UserPoolId)
log.Println("a.UserPoolSecret", a.UserPoolSecret)
if a.TenantId != nil {
log.Println("a.TenantId", *a.TenantId)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/carlmax_my/console-core-go.git
git@gitee.com:carlmax_my/console-core-go.git
carlmax_my
console-core-go
console-core-go
v0.0.46

搜索帮助