Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
9961a1df
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
9961a1df
编写于
10月 09, 2020
作者:
K
KubeSphere CI Bot
提交者:
GitHub
10月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2997 from lxm/oauth-aliyunidaas
support aliyun idaas oauth login
上级
686dfef9
1a39d62f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
148 addition
and
1 deletion
+148
-1
pkg/apiserver/authentication/identityprovider/aliyunidaas/idaas.go
...rver/authentication/identityprovider/aliyunidaas/idaas.go
+146
-0
pkg/apiserver/authentication/oauth/oauth_options.go
pkg/apiserver/authentication/oauth/oauth_options.go
+1
-1
pkg/apiserver/authentication/options/authenticate_options.go
pkg/apiserver/authentication/options/authenticate_options.go
+1
-0
未找到文件。
pkg/apiserver/authentication/identityprovider/aliyunidaas/idaas.go
0 → 100644
浏览文件 @
9961a1df
/*
Copyright 2020 The KubeSphere Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package
aliyunidaas
import
(
"context"
"encoding/json"
"errors"
"io/ioutil"
"golang.org/x/oauth2"
"gopkg.in/yaml.v3"
"kubesphere.io/kubesphere/pkg/apiserver/authentication/identityprovider"
"kubesphere.io/kubesphere/pkg/apiserver/authentication/oauth"
)
type
AliyunIDaaS
struct
{
// ClientID is the application's ID.
ClientID
string
`json:"clientID" yaml:"clientID"`
// ClientSecret is the application's secret.
ClientSecret
string
`json:"-" yaml:"clientSecret"`
// Endpoint contains the resource server's token endpoint
// URLs. These are constants specific to each server and are
// often available via site-specific packages, such as
// google.Endpoint or github.Endpoint.
Endpoint
Endpoint
`json:"endpoint" yaml:"endpoint"`
// RedirectURL is the URL to redirect users going through
// the OAuth flow, after the resource owner's URLs.
RedirectURL
string
`json:"redirectURL" yaml:"redirectURL"`
// Scope specifies optional requested permissions.
Scopes
[]
string
`json:"scopes" yaml:"scopes"`
}
// Endpoint represents an OAuth 2.0 provider's authorization and token
// endpoint URLs.
type
Endpoint
struct
{
AuthURL
string
`json:"authURL" yaml:"authURL"`
TokenURL
string
`json:"tokenURL" yaml:"tokenURL"`
UserInfoURL
string
`json:"user_info_url" yaml:"userInfoUrl"`
}
type
IDaaSIdentity
struct
{
Sub
string
`json:"sub"`
OuID
string
`json:"ou_id"`
Nickname
string
`json:"nickname"`
PhoneNumber
string
`json:"phone_number"`
OuName
string
`json:"ou_name"`
Email
string
`json:"email"`
Username
string
`json:"username"`
}
type
UserInfoResp
struct
{
Success
bool
`json:"success"`
Message
string
`json:"message"`
Code
string
`json:"code"`
IDaaSIdentity
IDaaSIdentity
`json:"data"`
}
func
init
()
{
identityprovider
.
RegisterOAuthProvider
(
&
AliyunIDaaS
{})
}
func
(
a
*
AliyunIDaaS
)
Type
()
string
{
return
"AliyunIDaasProvider"
}
func
(
a
*
AliyunIDaaS
)
Setup
(
options
*
oauth
.
DynamicOptions
)
(
identityprovider
.
OAuthProvider
,
error
)
{
data
,
err
:=
yaml
.
Marshal
(
options
)
if
err
!=
nil
{
return
nil
,
err
}
var
provider
AliyunIDaaS
err
=
yaml
.
Unmarshal
(
data
,
&
provider
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
provider
,
nil
}
func
(
a
IDaaSIdentity
)
GetName
()
string
{
return
a
.
Username
}
func
(
a
IDaaSIdentity
)
GetEmail
()
string
{
return
a
.
Email
}
func
(
g
*
AliyunIDaaS
)
IdentityExchange
(
code
string
)
(
identityprovider
.
Identity
,
error
)
{
config
:=
oauth2
.
Config
{
ClientID
:
g
.
ClientID
,
ClientSecret
:
g
.
ClientSecret
,
Endpoint
:
oauth2
.
Endpoint
{
AuthURL
:
g
.
Endpoint
.
AuthURL
,
TokenURL
:
g
.
Endpoint
.
TokenURL
,
AuthStyle
:
oauth2
.
AuthStyleAutoDetect
,
},
RedirectURL
:
g
.
RedirectURL
,
Scopes
:
g
.
Scopes
,
}
token
,
err
:=
config
.
Exchange
(
context
.
Background
(),
code
)
if
err
!=
nil
{
return
nil
,
err
}
resp
,
err
:=
oauth2
.
NewClient
(
context
.
Background
(),
oauth2
.
StaticTokenSource
(
token
))
.
Get
(
g
.
Endpoint
.
UserInfoURL
)
if
err
!=
nil
{
return
nil
,
err
}
data
,
err
:=
ioutil
.
ReadAll
(
resp
.
Body
)
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
return
nil
,
err
}
var
UserInfoResp
UserInfoResp
err
=
json
.
Unmarshal
(
data
,
&
UserInfoResp
)
if
err
!=
nil
{
return
nil
,
err
}
if
!
UserInfoResp
.
Success
{
return
nil
,
errors
.
New
(
UserInfoResp
.
Message
)
}
return
UserInfoResp
.
IDaaSIdentity
,
nil
}
pkg/apiserver/authentication/oauth/oauth_options.go
浏览文件 @
9961a1df
...
...
@@ -93,7 +93,7 @@ type IdentityProviderOptions struct {
Type
string
`json:"type" yaml:"type"`
// The options of identify provider
Provider
*
DynamicOptions
`json:"
-
" yaml:"provider"`
Provider
*
DynamicOptions
`json:"
provider
" yaml:"provider"`
}
type
Token
struct
{
...
...
pkg/apiserver/authentication/options/authenticate_options.go
浏览文件 @
9961a1df
...
...
@@ -19,6 +19,7 @@ package options
import
(
"fmt"
"github.com/spf13/pflag"
_
"kubesphere.io/kubesphere/pkg/apiserver/authentication/identityprovider/aliyunidaas"
_
"kubesphere.io/kubesphere/pkg/apiserver/authentication/identityprovider/github"
"kubesphere.io/kubesphere/pkg/apiserver/authentication/oauth"
"time"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录