Blame view

frontend/manage/src/api/auth.js 1.37 KB
8d73e917   陈威   初始化提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import req from '@/request.js'
const auth = window.context.auth || ''

export default {
  getAuthorizeMessage(){
    return req.get(`${auth}/authorize/v1/get`)
  },
  authentication(principal, cb, errorCb) {
    let Base64 = require('js-base64').Base64
    req
      .post(auth + `/auth?tenantId=${principal.tenantId || '-1'}`, {
        username: principal.account,
        password: principal.password.encryptWithRsa(),
        verificationKey: principal.verificationKey,
        verificationCode: principal.verificationCode
      })
      .then(function(rep) {
        cb(rep.data)
      })
      .catch(function(error) {
        errorCb(error.message)
      })
  },
  basicSso(token, cb, errorCb) {
    let service = localStorage.getItem('service')
    req
      .get(auth + `/sso/auth?ticket=${token}&code=${token}&service=${service}`)
      .then(function(rep) {
        cb(rep.data)
      })
      .catch(function(error) {
        errorCb(error.message)
      })
  },
  refreshAndGetAuthenticationToken() {
    return new Promise((resolve, reject) => {
      req
        .get(`${auth}/refresh`)
        .then(function(rep) {
          resolve(rep.data)
        })
        .catch(function(error) {
          reject(error.message)
        })
    })
  },
  logout() {
    return req.get(`${auth}/signout`)
  },
  getCaptcha(){
    return req.get('${auth}/auth/captcha?' + Math.random())
  },
}