Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Sunny_yiyi
Swagger Ui
提交
8b81bcac
S
Swagger Ui
项目概览
Sunny_yiyi
/
Swagger Ui
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Swagger Ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8b81bcac
编写于
10月 11, 2017
作者:
K
Kyle Shockey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
OAS3 Auth MVP
上级
fa24b6ae
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
186 addition
and
23 deletion
+186
-23
dev-helpers/oauth2-redirect.html
dev-helpers/oauth2-redirect.html
+4
-1
dist/oauth2-redirect.html
dist/oauth2-redirect.html
+4
-1
src/core/components/auth/oauth2.jsx
src/core/components/auth/oauth2.jsx
+11
-6
src/core/oauth2-authorize.js
src/core/oauth2-authorize.js
+10
-0
src/core/plugins/auth/selectors.js
src/core/plugins/auth/selectors.js
+3
-3
src/core/plugins/oas3/auth-extensions/wrap-selectors.js
src/core/plugins/oas3/auth-extensions/wrap-selectors.js
+33
-11
src/core/plugins/oas3/spec-extensions/wrap-selectors.js
src/core/plugins/oas3/spec-extensions/wrap-selectors.js
+5
-1
test/core/plugins/oas3/wrap-auth-selectors.js
test/core/plugins/oas3/wrap-auth-selectors.js
+116
-0
未找到文件。
dev-helpers/oauth2-redirect.html
浏览文件 @
8b81bcac
...
...
@@ -27,7 +27,10 @@
isValid
=
qp
.
state
===
sentState
if
(
oauth2
.
auth
.
schema
.
get
(
"
flow
"
)
===
"
accessCode
"
&&
!
oauth2
.
auth
.
code
)
{
if
((
oauth2
.
auth
.
schema
.
get
(
"
flow
"
)
===
"
accessCode
"
||
oauth2
.
auth
.
schema
.
get
(
"
flow
"
)
===
"
authorizationCode
"
)
&&
!
oauth2
.
auth
.
code
)
{
if
(
!
isValid
)
{
oauth2
.
errCb
({
authId
:
oauth2
.
auth
.
name
,
...
...
dist/oauth2-redirect.html
浏览文件 @
8b81bcac
...
...
@@ -27,7 +27,10 @@
isValid
=
qp
.
state
===
sentState
if
(
oauth2
.
auth
.
schema
.
get
(
"
flow
"
)
===
"
accessCode
"
&&
!
oauth2
.
auth
.
code
)
{
if
((
oauth2
.
auth
.
schema
.
get
(
"
flow
"
)
===
"
accessCode
"
||
oauth2
.
auth
.
schema
.
get
(
"
flow
"
)
===
"
authorizationCode
"
)
&&
!
oauth2
.
auth
.
code
)
{
if
(
!
isValid
)
{
oauth2
.
errCb
({
authId
:
oauth2
.
auth
.
name
,
...
...
src/core/components/auth/oauth2.jsx
浏览文件 @
8b81bcac
...
...
@@ -2,11 +2,6 @@ import React from "react"
import
PropTypes
from
"
prop-types
"
import
oauth2Authorize
from
"
core/oauth2-authorize
"
const
IMPLICIT
=
"
implicit
"
const
ACCESS_CODE
=
"
accessCode
"
const
PASSWORD
=
"
password
"
const
APPLICATION
=
"
application
"
export
default
class
Oauth2
extends
React
.
Component
{
static
propTypes
=
{
name
:
PropTypes
.
string
,
...
...
@@ -83,7 +78,9 @@ export default class Oauth2 extends React.Component {
}
render
()
{
let
{
schema
,
getComponent
,
authSelectors
,
errSelectors
,
name
}
=
this
.
props
let
{
schema
,
getComponent
,
authSelectors
,
errSelectors
,
name
,
specSelectors
}
=
this
.
props
const
Input
=
getComponent
(
"
Input
"
)
const
Row
=
getComponent
(
"
Row
"
)
const
Col
=
getComponent
(
"
Col
"
)
...
...
@@ -92,6 +89,14 @@ export default class Oauth2 extends React.Component {
const
JumpToPath
=
getComponent
(
"
JumpToPath
"
,
true
)
const
Markdown
=
getComponent
(
"
Markdown
"
)
const
{
isOAS3
}
=
specSelectors
// Auth type consts
const
IMPLICIT
=
"
implicit
"
const
PASSWORD
=
"
password
"
const
ACCESS_CODE
=
isOAS3
()
?
"
authorizationCode
"
:
"
accessCode
"
const
APPLICATION
=
isOAS3
()
?
"
clientCredentials
"
:
"
application
"
let
flow
=
schema
.
get
(
"
flow
"
)
let
scopes
=
schema
.
get
(
"
allowedScopes
"
)
||
schema
.
get
(
"
scopes
"
)
let
authorizedAuth
=
authSelectors
.
authorized
().
get
(
name
)
...
...
src/core/oauth2-authorize.js
浏览文件 @
8b81bcac
...
...
@@ -22,6 +22,16 @@ export default function authorize ( { auth, authActions, errActions, configs, au
case
"
implicit
"
:
query
.
push
(
"
response_type=token
"
)
break
case
"
clientCredentials
"
:
// OAS3
authActions
.
authorizeApplication
(
auth
)
return
case
"
authorizationCode
"
:
// OAS3
query
.
push
(
"
response_type=code
"
)
break
}
if
(
typeof
clientId
===
"
string
"
)
{
...
...
src/core/plugins/auth/selectors.js
浏览文件 @
8b81bcac
...
...
@@ -10,7 +10,7 @@ export const shownDefinitions = createSelector(
export
const
definitionsToAuthorize
=
createSelector
(
state
,
()
=>
(
{
specSelectors
}
)
=>
{
()
=>
(
{
specSelectors
}
)
=>
{
let
definitions
=
specSelectors
.
securityDefinitions
()
let
list
=
List
()
...
...
@@ -27,7 +27,7 @@ export const definitionsToAuthorize = createSelector(
)
export
const
getDefinitionsByNames
=
(
state
,
securities
)
=>
(
{
specSelectors
}
)
=>
{
export
const
getDefinitionsByNames
=
(
state
,
securities
)
=>
(
{
specSelectors
}
)
=>
{
let
securityDefinitions
=
specSelectors
.
securityDefinitions
()
let
result
=
List
()
...
...
@@ -64,7 +64,7 @@ export const authorized = createSelector(
)
export
const
isAuthorized
=
(
state
,
securities
)
=>
(
{
authSelectors
}
)
=>
{
export
const
isAuthorized
=
(
state
,
securities
)
=>
(
{
authSelectors
}
)
=>
{
let
authorized
=
authSelectors
.
authorized
()
if
(
!
List
.
isList
(
securities
))
{
...
...
src/core/plugins/oas3/auth-extensions/wrap-selectors.js
浏览文件 @
8b81bcac
import
{
createSelector
}
from
"
reselect
"
import
{
List
}
from
"
immutable
"
import
{
List
,
Map
,
fromJS
}
from
"
immutable
"
import
{
isOAS3
as
isOAS3Helper
}
from
"
../helpers
"
// Helpers
const
state
=
state
=>
state
function
onlyOAS3
(
selector
)
{
return
(
ori
,
system
)
=>
(...
args
)
=>
{
const
spec
=
system
.
getSystem
().
specSelectors
.
specJson
()
if
(
isOAS3Helper
(
spec
))
{
return
selector
(...
args
)
return
selector
(
system
,
...
args
)
}
else
{
return
ori
(...
args
)
}
}
}
const
nullSelector
=
createSelector
(()
=>
null
)
export
const
definitionsToAuthorize
=
onlyOAS3
(
createSelector
(
state
,
({
specSelectors
})
=>
{
// Coerce our OpenAPI 3.0 definitions into monoflow definitions
// that look like Swagger2 definitions.
let
definitions
=
specSelectors
.
securityDefinitions
()
let
list
=
List
()
definitions
.
entrySeq
().
forEach
(
([
defName
,
definition
])
=>
{
definition
.
get
(
"
flows
"
).
entrySeq
().
forEach
(([
flowKey
,
flowVal
])
=>
{
let
translatedDef
=
fromJS
({
flow
:
flowKey
,
authorizationUrl
:
flowVal
.
get
(
"
authorizationUrl
"
),
tokenUrl
:
flowVal
.
get
(
"
tokenUrl
"
),
scopes
:
flowVal
.
get
(
"
scopes
"
),
type
:
definition
.
get
(
"
type
"
)
})
const
OAS3NullSelector
=
onlyOAS3
(
nullSelector
)
list
=
list
.
push
(
new
Map
({
[
defName
]:
translatedDef
.
filter
((
v
)
=>
{
// filter out unset values, sometimes `authorizationUrl`
// and `tokenUrl` come out as `undefined` in the data
return
v
!==
undefined
})
}))
})
})
// Hasta la vista, authentication!
export
const
shownDefinitions
=
OAS3NullSelector
export
const
definitionsToAuthorize
=
OAS3NullSelector
export
const
getDefinitionsByNames
=
OAS3NullSelector
export
const
authorized
=
onlyOAS3
(()
=>
List
())
export
const
isAuthorized
=
OAS3NullSelector
export
const
getConfigs
=
OAS3NullSelector
return
list
}
))
src/core/plugins/oas3/spec-extensions/wrap-selectors.js
浏览文件 @
8b81bcac
...
...
@@ -48,12 +48,16 @@ export const definitions = onlyOAS3(createSelector(
spec
=>
spec
.
getIn
([
"
components
"
,
"
schemas
"
])
||
Map
()
))
export
const
securityDefinitions
=
onlyOAS3
(
createSelector
(
spec
,
spec
=>
spec
.
getIn
([
"
components
"
,
"
securitySchemes
"
])
||
Map
()
))
export
const
host
=
OAS3NullSelector
export
const
basePath
=
OAS3NullSelector
export
const
consumes
=
OAS3NullSelector
export
const
produces
=
OAS3NullSelector
export
const
schemes
=
OAS3NullSelector
export
const
securityDefinitions
=
OAS3NullSelector
// New selectors
...
...
test/core/plugins/oas3/wrap-auth-selectors.js
0 → 100644
浏览文件 @
8b81bcac
/* eslint-env mocha */
import
expect
,
{
createSpy
}
from
"
expect
"
import
{
Map
,
fromJS
}
from
"
immutable
"
import
{
definitionsToAuthorize
}
from
"
corePlugins/oas3/auth-extensions/wrap-selectors
"
describe
.
only
(
"
oas3 plugin - auth extensions - wrapSelectors
"
,
function
(){
describe
(
"
execute
"
,
function
(){
it
(
"
should add `securities` to the oriAction call
"
,
function
(){
// Given
const
system
=
{
getSystem
:
()
=>
system
,
specSelectors
:
{
specJson
:
()
=>
fromJS
({
openapi
:
"
3.0.0
"
}),
securityDefinitions
:
()
=>
{
return
fromJS
({
"
oauth2AuthorizationCode
"
:
{
"
type
"
:
"
oauth2
"
,
"
flows
"
:
{
"
authorizationCode
"
:
{
"
authorizationUrl
"
:
"
http://google.com/
"
,
"
tokenUrl
"
:
"
http://google.com/
"
,
"
scopes
"
:
{
"
myScope
"
:
"
our only scope
"
}
}
}
},
"
oauth2Multiflow
"
:
{
"
type
"
:
"
oauth2
"
,
"
flows
"
:
{
"
clientCredentials
"
:
{
"
tokenUrl
"
:
"
http://google.com/
"
,
"
scopes
"
:
{
"
myScope
"
:
"
our only scope
"
}
},
"
password
"
:
{
"
tokenUrl
"
:
"
http://google.com/
"
,
"
scopes
"
:
{
"
myScope
"
:
"
our only scope
"
}
},
"
authorizationCode
"
:
{
"
authorizationUrl
"
:
"
http://google.com/
"
,
"
tokenUrl
"
:
"
http://google.com/
"
,
"
scopes
"
:
{
"
myScope
"
:
"
our only scope
"
}
}
}
}
})
}
}
}
// When
let
res
=
definitionsToAuthorize
(()
=>
null
,
system
)()
// Then
expect
(
res
.
toJS
()).
toEqual
([
{
oauth2AuthorizationCode
:
{
flow
:
"
authorizationCode
"
,
authorizationUrl
:
"
http://google.com/
"
,
tokenUrl
:
"
http://google.com/
"
,
scopes
:
{
"
myScope
"
:
"
our only scope
"
},
type
:
"
oauth2
"
}
},
{
oauth2Multiflow
:
{
flow
:
"
clientCredentials
"
,
tokenUrl
:
"
http://google.com/
"
,
scopes
:
{
"
myScope
"
:
"
our only scope
"
},
type
:
"
oauth2
"
}
},
{
oauth2Multiflow
:
{
flow
:
"
password
"
,
tokenUrl
:
"
http://google.com/
"
,
scopes
:
{
"
myScope
"
:
"
our only scope
"
},
type
:
"
oauth2
"
}
},
{
oauth2Multiflow
:
{
flow
:
"
authorizationCode
"
,
authorizationUrl
:
"
http://google.com/
"
,
tokenUrl
:
"
http://google.com/
"
,
scopes
:
{
"
myScope
"
:
"
our only scope
"
},
type
:
"
oauth2
"
}
},
])
})
})
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录