diff --git a/cmd/climc/shell/identity/identityproviders.go b/cmd/climc/shell/identity/identityproviders.go index 64c7bcfa70..a25db198da 100644 --- a/cmd/climc/shell/identity/identityproviders.go +++ b/cmd/climc/shell/identity/identityproviders.go @@ -576,6 +576,30 @@ func init() { return nil }) + type IdentityProviderCreateGoogleOIDCOptions struct { + NAME string `help:"name of identity provider" json:"name"` + + api.SOIDCGoogleConfigOptions + + IdentityProviderCreateCommonOptions + } + R(&IdentityProviderCreateGoogleOIDCOptions{}, "idp-create-google-oidc", "Create an identity provider with Google OpenID Connect", func(s *mcclient.ClientSession, args *IdentityProviderCreateGoogleOIDCOptions) error { + params := jsonutils.NewDict() + params.Add(jsonutils.NewString("oidc"), "driver") + params.Add(jsonutils.NewString(api.IdpTemplateGoogle), "template") + + params.Update(jsonutils.Marshal(args)) + + params.Add(jsonutils.Marshal(args.SOIDCGoogleConfigOptions), "config", "oidc") + + idp, err := modules.IdentityProviders.Create(s, params) + if err != nil { + return err + } + printObject(idp) + return nil + }) + type IdentityProviderCreateAzureOIDCOptions struct { NAME string `help:"name of identity provider" json:"name"` diff --git a/pkg/apis/identity/config.go b/pkg/apis/identity/config.go index 683d0d9b4c..f1129ad36f 100644 --- a/pkg/apis/identity/config.go +++ b/pkg/apis/identity/config.go @@ -95,6 +95,7 @@ const ( IdpTemplateDex = "dex_oidc" IdpTemplateGithub = "github_oidc" IdpTemplateAzureOAuth2 = "azure_oidc" + IdpTemplateGoogle = "google_oidc" IdpTemplateAlipay = "alipay_oauth2" IdpTemplateWechat = "wechat_oauth2" diff --git a/pkg/apis/identity/oidc.go b/pkg/apis/identity/oidc.go index 1ddc9dd82b..b53f0cd524 100644 --- a/pkg/apis/identity/oidc.go +++ b/pkg/apis/identity/oidc.go @@ -46,6 +46,13 @@ type SOIDCGithubConfigOptions struct { SIdpAttributeOptions } +type SOIDCGoogleConfigOptions struct { + ClientId string `json:"client_id"` + ClientSecret string `json:"client_secret"` + + SIdpAttributeOptions +} + const ( AZURE_CLOUD_ENV_CHINA = "china" AZURE_CLOUD_ENV_GLOBAL = "global" diff --git a/pkg/keystone/driver/oidc/oidc.go b/pkg/keystone/driver/oidc/oidc.go index 00ac2eeb63..3696930659 100644 --- a/pkg/keystone/driver/oidc/oidc.go +++ b/pkg/keystone/driver/oidc/oidc.go @@ -73,6 +73,8 @@ func (self *SOIDCDriver) prepareConfig() error { conf = DexOIDCTemplate case api.IdpTemplateGithub: conf = GithubOIDCTemplate + case api.IdpTemplateGoogle: + conf = GoogleOIDCTemplate case api.IdpTemplateAzureOAuth2: conf = AzureADTemplate tenantId, _ := confJson.GetString("tenant_id") diff --git a/pkg/keystone/driver/oidc/template.go b/pkg/keystone/driver/oidc/template.go index 5bacecf43b..d66bd8468d 100644 --- a/pkg/keystone/driver/oidc/template.go +++ b/pkg/keystone/driver/oidc/template.go @@ -53,6 +53,26 @@ var ( }, } + // { + // "sub": "112176790568447731603", + // "name": "Jian Qiu", + // "given_name": "Jian", + // "family_name": "Qiu", + // "picture": "https://lh3.googleusercontent.com/a/AATXAJyj32UmKhmwI38ljm8xI53LX4Lw3w5wYxKsj4JS\u003ds96-c", + // "email": "swordqiu@gmail.com", + // "email_verified": true, + // "locale": "zh-CN" + // } + GoogleOIDCTemplate = api.SOIDCIdpConfigOptions{ + Endpoint: "https://accounts.google.com", + SIdpAttributeOptions: api.SIdpAttributeOptions{ + UserIdAttribute: "sub", + UserNameAttribute: "email", + UserEmailAttribute: "email", + UserDisplaynameAttribtue: "name", + }, + } + AzureADTemplate = api.SOIDCIdpConfigOptions{ Scopes: []string{ "openid",