Merge pull request #11551 from influxdata/feat/move-auth-to-external-client
Move authentication to external clientpull/11552/head
commit
c601b4501c
|
@ -828,6 +828,14 @@
|
||||||
"integrity": "sha512-I2EjI9TbEFJNLziNPFfpo64PNanOaK17iL2kTW/jGlGOa4bvHw4VEied83kOEB7NJjXf1KfvmsQ2aEjy3xjiGg==",
|
"integrity": "sha512-I2EjI9TbEFJNLziNPFfpo64PNanOaK17iL2kTW/jGlGOa4bvHw4VEied83kOEB7NJjXf1KfvmsQ2aEjy3xjiGg==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"@influxdata/influx": {
|
||||||
|
"version": "0.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@influxdata/influx/-/influx-0.1.1.tgz",
|
||||||
|
"integrity": "sha512-ANHGcrjXc5PRZfeAknkGIvQbNb8eI3I8iqTxPLKZHQvqQm3SD3brbE5CV+Qt/iRsszu3beIL2CjUBrU+wQLcWg==",
|
||||||
|
"requires": {
|
||||||
|
"axios": "^0.18.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@mrmlnc/readdir-enhanced": {
|
"@mrmlnc/readdir-enhanced": {
|
||||||
"version": "2.2.1",
|
"version": "2.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/@mrmlnc/readdir-enhanced/-/readdir-enhanced-2.2.1.tgz",
|
||||||
|
|
|
@ -114,6 +114,7 @@
|
||||||
"typescript": "^3.1.3"
|
"typescript": "^3.1.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@influxdata/influx": "^0.1.1",
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
"babel-polyfill": "^6.26.0",
|
"babel-polyfill": "^6.26.0",
|
||||||
"bignumber.js": "^4.0.2",
|
"bignumber.js": "^4.0.2",
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {PureComponent} from 'react'
|
||||||
import {withRouter, WithRouterProps} from 'react-router'
|
import {withRouter, WithRouterProps} from 'react-router'
|
||||||
|
|
||||||
// APIs
|
// APIs
|
||||||
import {logout} from 'src/me/apis'
|
import {client} from 'src/utils/api'
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import {ErrorHandling} from 'src/shared/decorators/errors'
|
import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
|
@ -21,7 +21,7 @@ export class Logout extends PureComponent<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleSignOut = async () => {
|
private handleSignOut = async () => {
|
||||||
await logout()
|
await client.auth.signout()
|
||||||
|
|
||||||
this.props.router.push(`/signin`)
|
this.props.router.push(`/signin`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import {baseAPI} from 'src/utils/api'
|
import {client} from 'src/utils/api'
|
||||||
|
|
||||||
export const logout = async (): Promise<void> => {
|
export const logout = async (): Promise<void> => {
|
||||||
await baseAPI.signoutPost()
|
await client.auth.signout()
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@ import {SetupSuccess, SetupError} from 'src/shared/copy/notifications'
|
||||||
// Actions
|
// Actions
|
||||||
import {notify} from 'src/shared/actions/notifications'
|
import {notify} from 'src/shared/actions/notifications'
|
||||||
|
|
||||||
|
import {client} from 'src/utils/api'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {
|
import {
|
||||||
SetupParams,
|
SetupParams,
|
||||||
signin as signinAJAX,
|
|
||||||
setSetupParams as setSetupParamsAJAX,
|
setSetupParams as setSetupParamsAJAX,
|
||||||
} from 'src/onboarding/apis'
|
} from 'src/onboarding/apis'
|
||||||
|
|
||||||
|
@ -75,10 +76,9 @@ export const setupAdmin = (setupParams: SetupParams) => async dispatch => {
|
||||||
dispatch(setOrganizationID(orgID))
|
dispatch(setOrganizationID(orgID))
|
||||||
dispatch(setBucketID(bucketID))
|
dispatch(setBucketID(bucketID))
|
||||||
|
|
||||||
await signinAJAX({
|
const {username, password} = setupParams
|
||||||
username: setupParams.username,
|
|
||||||
password: setupParams.password,
|
await client.auth.signin(username, password)
|
||||||
})
|
|
||||||
dispatch(notify(SetupSuccess))
|
dispatch(notify(SetupSuccess))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Libraries
|
// Libraries
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
|
|
||||||
import {baseAPI, setupAPI, sourcesAPI} from 'src/utils/api'
|
import {setupAPI, sourcesAPI} from 'src/utils/api'
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import {
|
import {
|
||||||
|
@ -10,6 +10,7 @@ import {
|
||||||
writeAPI,
|
writeAPI,
|
||||||
scraperTargetsApi,
|
scraperTargetsApi,
|
||||||
} from 'src/utils/api'
|
} from 'src/utils/api'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Telegraf,
|
Telegraf,
|
||||||
WritePrecision,
|
WritePrecision,
|
||||||
|
@ -68,19 +69,6 @@ export const setSetupParams = async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const signin = async (params: {
|
|
||||||
username: string
|
|
||||||
password: string
|
|
||||||
}): Promise<void> => {
|
|
||||||
const {username, password} = params
|
|
||||||
try {
|
|
||||||
await baseAPI.signinPost({auth: {username, password}})
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Sign in has failed', error)
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const trySources = async (): Promise<boolean> => {
|
export const trySources = async (): Promise<boolean> => {
|
||||||
try {
|
try {
|
||||||
await sourcesAPI.sourcesGet('')
|
await sourcesAPI.sourcesGet('')
|
||||||
|
|
|
@ -20,7 +20,7 @@ import {
|
||||||
} from 'src/clockface'
|
} from 'src/clockface'
|
||||||
|
|
||||||
// APIs
|
// APIs
|
||||||
import {signin} from 'src/onboarding/apis'
|
import {client} from 'src/utils/api'
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
import {notify as notifyAction} from 'src/shared/actions/notifications'
|
import {notify as notifyAction} from 'src/shared/actions/notifications'
|
||||||
|
@ -107,7 +107,7 @@ class SigninForm extends PureComponent<Props, State> {
|
||||||
const {username, password} = this.state
|
const {username, password} = this.state
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await signin({username, password})
|
await client.auth.signin(username, password)
|
||||||
this.handleRedirect()
|
this.handleRedirect()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = get(error, 'response.data.msg', '')
|
const message = get(error, 'response.data.msg', '')
|
||||||
|
|
|
@ -18,8 +18,12 @@ import {
|
||||||
LabelsApi,
|
LabelsApi,
|
||||||
} from 'src/api'
|
} from 'src/api'
|
||||||
|
|
||||||
|
import Client from '@influxdata/influx'
|
||||||
|
|
||||||
const basePath = '/api/v2'
|
const basePath = '/api/v2'
|
||||||
|
|
||||||
|
export const client = new Client(basePath)
|
||||||
|
|
||||||
export const baseAPI = new DefaultApi({basePath})
|
export const baseAPI = new DefaultApi({basePath})
|
||||||
export const viewsAPI = new ViewsApi({basePath})
|
export const viewsAPI = new ViewsApi({basePath})
|
||||||
export const taskAPI = new TasksApi({basePath})
|
export const taskAPI = new TasksApi({basePath})
|
||||||
|
|
Loading…
Reference in New Issue