2018-01-22 15:53:39 -08:00
|
|
|
import Base from 'ember-simple-auth/authenticators/base';
|
2020-09-29 16:04:25 -07:00
|
|
|
import { IAuthenticateResponse, IAuthenticationData } from '@datahub/shared/types/authentication/user';
|
2020-08-26 15:44:50 -07:00
|
|
|
import { postJSON } from '@datahub/utils/api/fetcher';
|
2018-01-22 17:31:48 -08:00
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
/**
|
|
|
|
* Custom authenticator for ldap user authentication
|
|
|
|
* @export
|
|
|
|
* @class CustomLdap
|
|
|
|
* @extends {Base}
|
|
|
|
*/
|
|
|
|
export default class CustomLdap extends Base {
|
2018-01-22 15:53:39 -08:00
|
|
|
/**
|
|
|
|
* Implements Base authenticator's authenticate method.
|
|
|
|
* Resolves with data object returned from successful request.
|
|
|
|
* @param {string} username username to authenticate with
|
|
|
|
* @param {string} password matching candidate password for username
|
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
async authenticate(username: string, password: string): Promise<IAuthenticationData> {
|
|
|
|
const { data } = await postJSON<IAuthenticateResponse>({
|
2018-01-22 15:53:39 -08:00
|
|
|
url: '/authenticate',
|
2020-08-26 15:44:50 -07:00
|
|
|
data: { username, password }
|
|
|
|
});
|
2018-01-22 15:53:39 -08:00
|
|
|
|
2020-08-26 15:44:50 -07:00
|
|
|
return data;
|
|
|
|
}
|
2018-01-22 15:53:39 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements the authenticator's restore method
|
|
|
|
*/
|
2020-08-26 15:44:50 -07:00
|
|
|
restore(): Promise<void> {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
}
|