mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-21 06:09:39 +08:00
feature: unified sso login framework
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
"yunion.io/x/onecloud/pkg/util/fileutils2"
|
||||
"yunion.io/x/onecloud/pkg/util/shellutils"
|
||||
)
|
||||
|
||||
@@ -55,6 +56,19 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type IdentityProviderUpdateOptions struct {
|
||||
ID string `help:"Id or name of identity provider to update" json:"-"`
|
||||
api.IdentityProviderUpdateInput
|
||||
}
|
||||
R(&IdentityProviderUpdateOptions{}, "idp-update", "Update a identity provider", func(s *mcclient.ClientSession, args *IdentityProviderUpdateOptions) error {
|
||||
resp, err := modules.IdentityProviders.Update(s, args.ID, jsonutils.Marshal(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(resp)
|
||||
return nil
|
||||
})
|
||||
|
||||
R(&IdentityProviderDetailOptions{}, "idp-config-show", "Show detail of a domain config", func(s *mcclient.ClientSession, args *IdentityProviderDetailOptions) error {
|
||||
conf, err := modules.IdentityProviders.GetSpecific(s, args.ID, "config", nil)
|
||||
if err != nil {
|
||||
@@ -525,4 +539,144 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type IdentityProviderCreateAzureOIDCOptions struct {
|
||||
NAME string `help:"name of identity provider" json:"-"`
|
||||
|
||||
api.SOIDCAzureConfigOptions
|
||||
}
|
||||
R(&IdentityProviderCreateAzureOIDCOptions{}, "idp-create-azure-oidc", "Create an identity provider with Azure AD OpenID Connect", func(s *mcclient.ClientSession, args *IdentityProviderCreateAzureOIDCOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
params.Add(jsonutils.NewString("oidc"), "driver")
|
||||
params.Add(jsonutils.NewString(api.IdpTemplateAzureOAuth2), "template")
|
||||
|
||||
params.Add(jsonutils.Marshal(args), "config", "oidc")
|
||||
|
||||
idp, err := modules.IdentityProviders.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(idp)
|
||||
return nil
|
||||
})
|
||||
|
||||
type IdentityProviderCreateAlipayOAuth2Options struct {
|
||||
NAME string `help:"name of identity provider"`
|
||||
APPID string `help:"Alipay app_id"`
|
||||
KEYFILE string `json:"Alipay app private key file"`
|
||||
}
|
||||
R(&IdentityProviderCreateAlipayOAuth2Options{}, "idp-create-alipay-oauth2", "Create an identity provider with Alipay OAuth2.0", func(s *mcclient.ClientSession, args *IdentityProviderCreateAlipayOAuth2Options) error {
|
||||
opts := api.SOAuth2IdpConfigOptions{}
|
||||
opts.AppId = args.APPID
|
||||
var err error
|
||||
opts.Secret, err = fileutils2.FileGetContents(args.KEYFILE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
params.Add(jsonutils.NewString("oauth2"), "driver")
|
||||
params.Add(jsonutils.NewString(api.IdpTemplateAlipay), "template")
|
||||
params.Add(jsonutils.Marshal(opts), "config", "oauth2")
|
||||
idp, err := modules.IdentityProviders.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(idp)
|
||||
return nil
|
||||
})
|
||||
|
||||
type IdentityProviderCreateFeishuOAuth2Options struct {
|
||||
NAME string `help:"name of identity provider"`
|
||||
|
||||
api.SOAuth2IdpConfigOptions
|
||||
}
|
||||
R(&IdentityProviderCreateFeishuOAuth2Options{}, "idp-create-feishu-oauth2", "Create an identity provider with Feishu OAuth2.0", func(s *mcclient.ClientSession, args *IdentityProviderCreateFeishuOAuth2Options) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
params.Add(jsonutils.NewString("oauth2"), "driver")
|
||||
params.Add(jsonutils.NewString(api.IdpTemplateFeishu), "template")
|
||||
params.Add(jsonutils.Marshal(args), "config", "oauth2")
|
||||
idp, err := modules.IdentityProviders.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(idp)
|
||||
return nil
|
||||
})
|
||||
|
||||
type IdentityProviderCreateDingtalkOAuth2Options struct {
|
||||
NAME string `help:"name of identity provider"`
|
||||
|
||||
api.SOAuth2IdpConfigOptions
|
||||
}
|
||||
R(&IdentityProviderCreateDingtalkOAuth2Options{}, "idp-create-dingtalk-oauth2", "Create an identity provider with Feishu OAuth2.0", func(s *mcclient.ClientSession, args *IdentityProviderCreateDingtalkOAuth2Options) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
params.Add(jsonutils.NewString("oauth2"), "driver")
|
||||
params.Add(jsonutils.NewString(api.IdpTemplateDingtalk), "template")
|
||||
params.Add(jsonutils.Marshal(args), "config", "oauth2")
|
||||
idp, err := modules.IdentityProviders.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(idp)
|
||||
return nil
|
||||
})
|
||||
|
||||
type IdentityProviderCreateWechatOAuth2Options struct {
|
||||
NAME string `help:"name of identity provider"`
|
||||
|
||||
api.SOAuth2IdpConfigOptions
|
||||
}
|
||||
R(&IdentityProviderCreateWechatOAuth2Options{}, "idp-create-wechat-oauth2", "Create an identity provider with Wechat OAuth2.0", func(s *mcclient.ClientSession, args *IdentityProviderCreateWechatOAuth2Options) error {
|
||||
params := jsonutils.NewDict()
|
||||
params.Add(jsonutils.NewString(args.NAME), "name")
|
||||
params.Add(jsonutils.NewString("oauth2"), "driver")
|
||||
params.Add(jsonutils.NewString(api.IdpTemplateWechat), "template")
|
||||
params.Add(jsonutils.Marshal(args), "config", "oauth2")
|
||||
idp, err := modules.IdentityProviders.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(idp)
|
||||
return nil
|
||||
})
|
||||
|
||||
type IdentityProviderCreateQywechatOAuth2Options struct {
|
||||
api.IdentityProviderCreateInput
|
||||
CorpId string `help:"corp id of qywechat"`
|
||||
AgentId string `help:"agent id of app"`
|
||||
Secret string `help:"secret of qywechat"`
|
||||
}
|
||||
R(&IdentityProviderCreateQywechatOAuth2Options{}, "idp-create-qywechat-oauth2", "Create an identity provider with Qiye Wechat OAuth2.0", func(s *mcclient.ClientSession, args *IdentityProviderCreateQywechatOAuth2Options) error {
|
||||
conf := api.SOAuth2IdpConfigOptions{
|
||||
AppId: fmt.Sprintf("%s/%s", args.CorpId, args.AgentId),
|
||||
Secret: args.Secret,
|
||||
}
|
||||
params := jsonutils.Marshal(args).(*jsonutils.JSONDict)
|
||||
params.Add(jsonutils.NewString("oauth2"), "driver")
|
||||
params.Add(jsonutils.NewString(api.IdpTemplateQywechat), "template")
|
||||
params.Add(jsonutils.Marshal(conf), "config", "oauth2")
|
||||
idp, err := modules.IdentityProviders.Create(s, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(idp)
|
||||
return nil
|
||||
})
|
||||
|
||||
type IdpGetRedirectUriOptions struct {
|
||||
ID string `help:"id or name of idp to query" json:"-"`
|
||||
|
||||
api.GetIdpSsoRedirectUriInput
|
||||
}
|
||||
R(&IdpGetRedirectUriOptions{}, "idp-sso-url", "Get sso url of a SSO idp", func(s *mcclient.ClientSession, args *IdpGetRedirectUriOptions) error {
|
||||
result, err := modules.IdentityProviders.GetSpecific(s, args.ID, "sso-redirect-uri", jsonutils.Marshal(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -169,6 +169,9 @@ func init() {
|
||||
SystemAccount bool `help:"is a system account?"`
|
||||
NoWebConsole bool `help:"allow web console access"`
|
||||
EnableMfa bool `help:"enable TOTP mfa"`
|
||||
|
||||
IdpId string `help:"Id of identity provider to link with"`
|
||||
IdpEntityId string `help:"Entity id of identity provider to link with"`
|
||||
}
|
||||
R(&UserCreateOptions{}, "user-create", "Create a user", func(s *mcclient.ClientSession, args *UserCreateOptions) error {
|
||||
params := jsonutils.NewDict()
|
||||
@@ -214,6 +217,11 @@ func init() {
|
||||
params.Add(jsonutils.JSONTrue, "enable_mfa")
|
||||
}
|
||||
|
||||
if len(args.IdpId) > 0 {
|
||||
params.Add(jsonutils.NewString(args.IdpId), "idp_id")
|
||||
params.Add(jsonutils.NewString(args.IdpEntityId), "idp_entity_id")
|
||||
}
|
||||
|
||||
/*if len(args.DefaultProject) > 0 {
|
||||
projId, err := modules.Projects.GetId(s, args.DefaultProject, nil)
|
||||
if err != nil {
|
||||
@@ -409,4 +417,25 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type UserLinkIdpOptions struct {
|
||||
USER string `help:"ID or name of user to operate" json:"-"`
|
||||
IdpId string `help:"Id of identity provider to link with" required:"true" json:"idp_id"`
|
||||
IdpEntityId string `help:"Id of entity in identity provider to link with" required:"true" json:"idp_entity_id"`
|
||||
}
|
||||
R(&UserLinkIdpOptions{}, "user-link-idp", "Link user with an entity in the speicified identity provider", func(s *mcclient.ClientSession, args *UserLinkIdpOptions) error {
|
||||
result, err := modules.UsersV3.PerformAction(s, args.USER, "link-idp", jsonutils.Marshal(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
R(&UserLinkIdpOptions{}, "user-unlink-idp", "Unlink user from an entity in the speicified identity provider", func(s *mcclient.ClientSession, args *UserLinkIdpOptions) error {
|
||||
result, err := modules.UsersV3.PerformAction(s, args.USER, "unlink-idp", jsonutils.Marshal(args))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user