提交 | 用户 | 时间
|
820397
|
1 |
import request from '@/config/axios' |
H |
2 |
|
|
3 |
// 获得授权信息 |
|
4 |
export const getAuthorize = (clientId: string) => { |
|
5 |
return request.get({ url: '/system/oauth2/authorize?clientId=' + clientId }) |
|
6 |
} |
|
7 |
|
|
8 |
// 发起授权 |
|
9 |
export const authorize = ( |
|
10 |
responseType: string, |
|
11 |
clientId: string, |
|
12 |
redirectUri: string, |
|
13 |
state: string, |
|
14 |
autoApprove: boolean, |
|
15 |
checkedScopes: string[], |
|
16 |
uncheckedScopes: string[] |
|
17 |
) => { |
|
18 |
// 构建 scopes |
|
19 |
const scopes = {} |
|
20 |
for (const scope of checkedScopes) { |
|
21 |
scopes[scope] = true |
|
22 |
} |
|
23 |
for (const scope of uncheckedScopes) { |
|
24 |
scopes[scope] = false |
|
25 |
} |
|
26 |
// 发起请求 |
|
27 |
return request.post({ |
|
28 |
url: '/system/oauth2/authorize', |
|
29 |
headers: { |
|
30 |
'Content-type': 'application/x-www-form-urlencoded' |
|
31 |
}, |
|
32 |
params: { |
|
33 |
response_type: responseType, |
|
34 |
client_id: clientId, |
|
35 |
redirect_uri: redirectUri, |
|
36 |
state: state, |
|
37 |
auto_approve: autoApprove, |
|
38 |
scope: JSON.stringify(scopes) |
|
39 |
} |
|
40 |
}) |
|
41 |
} |