1 Star 0 Fork 0

carlmax_my/console-core-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
authing_idp.go 5.88 KB
一键复制 编辑 原始数据 按行查看 历史
carlmax_my 提交于 2024-12-02 21:32 . init project
package authing_v2
import (
"fmt"
"log"
"net/http"
"github.com/Authing/authing-go-sdk/lib/model"
)
func (a *AuthingCli) CreateIdp(name, idpType string) (string, error) {
req := &model.CreateExtIdpRequest{
Name: name,
Type: idpType,
// TenantUd: tenantId,
}
resp, err := a.Cli.CreateExtIdp(req)
if err != nil {
log.Printf("CreateIdp.error[%+v]:%+v\n", req, resp)
return "", err
}
log.Printf("CreateIdp.success[%+v]:%+v\n", req, resp)
return resp.ID, nil
}
func (a *AuthingCli) UpdateIdp(idpId string, name string) error {
req := &model.UpdateExtIdpRequest{
Name: name,
}
resp, err := a.Cli.UpdateExtIdp(idpId, req)
if err != nil {
log.Printf("UpdateIdp.error[%+v]:%+v\n", req, resp)
return err
}
log.Printf("UpdateIdp.success[%+v]:%+v\n", req, resp)
return nil
}
func (a *AuthingCli) DeleteIdp(idpId string) error {
resp, err := a.Cli.DeleteExtIdp(idpId)
if err != nil {
log.Printf("DeleteIdp.error[%s]:%+v\n", idpId, resp)
return err
}
log.Printf("DeleteIdp.success[%s]:%+v\n", idpId, resp)
return nil
}
func (a *AuthingCli) CreateIdp4Tenant(name, idpType, tenantId string) (string, error) {
req := &model.CreateExtIdpRequest{
Name: name,
Type: idpType,
TenantUd: tenantId,
}
resp, err := a.Cli.CreateExtIdp(req)
if err != nil {
log.Printf("CreateIdp4Tenant.error[%+v]:%+v\n", req, resp)
return "", err
}
log.Printf("CreateIdp4Tenant.success[%+v]:%+v\n", req, resp)
return resp.ID, nil
}
func (a *AuthingCli) UpdateIdp4Tenant(idpId string, tenantId string, name string) error {
req := &model.UpdateExtIdpRequest{
Name: name,
}
resp, err := a.Cli.UpdateExtIdp(idpId, req)
if err != nil {
log.Printf("UpdateIdp4Tenant.error[%+v]:%+v\n", req, resp)
return err
}
log.Printf("UpdateIdp4Tenant.success[%+v]:%+v\n", req, resp)
return nil
}
func (a *AuthingCli) DeleteIdp4Tenant(idpId string, tenantId string) error {
resp, err := a.Cli.DeleteExtIdp(idpId)
if err != nil {
log.Println("DeleteIdp4Tenant.error", resp)
return err
}
log.Println("DeleteIdp4Tenant.success", resp)
return nil
}
func (a *AuthingCli) CreateIdpConnection4Tenant(idpId string, tenantId string, connType string, identifier string, displayName string, fields interface{}) (string, error) {
req := &model.CreateExtIdpConnectionRequest{
ExtIdpId: idpId,
Type: connType,
Identifier: identifier,
DisplayName: displayName,
Fields: fields,
Logo: "",
// UserMatchFields: userMatchFields,
}
resp, err := a.Cli.CreateExtIdpConnection(req)
if err != nil {
return "", err
}
return resp.ID, nil
}
func (a *AuthingCli) UpdateIdpConnection4Tenant(idpConnectionId string, tenantId string, displayName string, fields interface{}) error {
req := &model.UpdateExtIdpConnectionRequest{
DisplayName: displayName,
Fields: fields,
Logo: "",
//UserMatchFields: userMatchFields,
}
resp, err := a.Cli.UpdateExtIdpConnection(idpConnectionId, req)
if err != nil {
return err
}
log.Println("UpdateIdpConnection4Tenant", resp)
return nil
}
func (a *AuthingCli) DeleteIdpConnection4Tenant(idpConnectionId string, tenantId string) error {
resp, err := a.Cli.DeleteExtIdpConnection(idpConnectionId)
if err != nil {
return err
}
log.Println("DeleteIdpConnection4Tenant", resp)
return nil
}
func (a *AuthingCli) CreateIdpConnection(idpId string, connType string, identifier string, displayName string, fields interface{}) (string, error) {
req := &model.CreateExtIdpConnectionRequest{
ExtIdpId: idpId,
Type: connType,
Identifier: identifier,
DisplayName: displayName,
Fields: fields,
Logo: "",
// UserMatchFields: userMatchFields,
}
resp, err := a.Cli.CreateExtIdpConnection(req)
if err != nil {
return "", err
}
return resp.ID, nil
}
func (a *AuthingCli) UpdateIdpConnection(idpConnectionId string, displayName string, fields interface{}) error {
req := &model.UpdateExtIdpConnectionRequest{
DisplayName: displayName,
Fields: fields,
Logo: "",
//UserMatchFields: userMatchFields,
}
resp, err := a.Cli.UpdateExtIdpConnection(idpConnectionId, req)
if err != nil {
return err
}
log.Println("UpdateIdpConnection.success", resp)
return nil
}
func (a *AuthingCli) DeleteIdpConnection(idpConnectionId string) error {
resp, err := a.Cli.DeleteExtIdpConnection(idpConnectionId)
if err != nil {
return err
}
log.Println("DeleteIdpConnection.success", resp)
return nil
}
func (a *AuthingCli) ChangeIdpConnectionState4App(idpConnectionId string, enable bool) error {
req := &model.ChangeExtIdpConnectionStateRequest{
Enabled: enable,
AppID: a.AuthCli.AppId,
}
_, err := a.Cli.ChangeExtIdpConnectionState(idpConnectionId, req)
return err
}
func (a *AuthingCli) ChangeIdpConnectionState4Tenant(idpConnectionId string, enable bool, tenantId string, isCreate bool) error {
req := &model.ChangeExtIdpConnectionStateRequest{
Enabled: enable,
AppID: a.AuthCli.AppId,
TenantID: tenantId,
}
_, err := a.Cli.ChangeExtIdpConnectionState(idpConnectionId, req)
return err
}
func (a *AuthingCli) AutoJoinUserToTenant(idpId string, enable bool, tenantId string) error {
c := a.Cli
url := fmt.Sprintf("%s/api/v2/extIdp/%s/autoJoin/%s", c.Host, idpId, tenantId)
req := &struct {
Enabled bool `json:"enabled"`
}{
Enabled: enable,
}
return a.SendAuthingRequest(url, http.MethodPut, req)
}
func (a *AuthingCli) ChangeIdpConnMfa(extConnId string, factor string, enable bool) error {
c := a.Cli
url := fmt.Sprintf("%s/api/v2/extIdpConn/%s", c.Host, extConnId)
req := &struct {
SkipMfa bool `json:"skipMfa"`
}{
SkipMfa: !enable,
}
return a.SendAuthingRequest(url, http.MethodPut, req)
}
func (a *AuthingCli) ChangeIdpConnectionMfa4Tenant(idpConnectionId string, tenantId string, EnabledFactors []string) error {
defFactor := "OTP"
if len(EnabledFactors) > 0 {
return a.ChangeIdpConnMfa(idpConnectionId, defFactor, true)
} else {
return a.ChangeIdpConnMfa(idpConnectionId, defFactor, false)
}
}
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.33

搜索帮助