index.ts 955 B

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