Merge pull request #11601 from swordqiu/feature/qj-google-oidc-identity-provider

Feature/qj google oidc identity provider
This commit is contained in:
Zexi Li
2021-07-09 10:00:00 +08:00
committed by GitHub
5 changed files with 55 additions and 0 deletions
@@ -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"`
+2
View File
@@ -95,6 +95,7 @@ const (
IdpTemplateDex = "dex_oidc"
IdpTemplateGithub = "github_oidc"
IdpTemplateAzureOAuth2 = "azure_oidc"
IdpTemplateGoogle = "google_oidc"
IdpTemplateAlipay = "alipay_oauth2"
IdpTemplateWechat = "wechat_oauth2"
@@ -115,6 +116,7 @@ var (
IdpTemplateDex: IdentityDriverOIDC,
IdpTemplateGithub: IdentityDriverOIDC,
IdpTemplateAzureOAuth2: IdentityDriverOIDC,
IdpTemplateGoogle: IdentityDriverOIDC,
IdpTemplateAlipay: IdentityDriverOAuth2,
IdpTemplateFeishu: IdentityDriverOAuth2,
+7
View File
@@ -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"
+2
View File
@@ -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")
+20
View File
@@ -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",