diff --git a/src/api/v2/clients/authnClient.ts b/src/api/v2/clients/authnClient.ts index 67a4608..9a63304 100644 --- a/src/api/v2/clients/authnClient.ts +++ b/src/api/v2/clients/authnClient.ts @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { IAuthnInfo, ILoginInfo, IPAICluster, IPAIResponse } from '@api/v2'; +import { ILoginInfo, IPAICluster, IPAIResponse } from '@api/v2'; import { Util } from '@pai/commom/util'; import { OpenPAIBaseClient } from './baseClient'; @@ -32,9 +32,10 @@ export class AuthnClient extends OpenPAIBaseClient { * Get an access token using username and password. * @param username Username, set undefined to use the username in cluster setting. * @param password Password, set undefined to use the password in cluster setting. + * @param expiration Expiration time in seconds, default 4000s. */ - public async basicLogin(username?: string, password?: string): Promise { - return await this.httpClient.login(username, password); + public async basicLogin(username?: string, password?: string, expiration?: number): Promise { + return await this.httpClient.login(username, password, expiration); } /** diff --git a/src/commom/paiHttpClient.ts b/src/commom/paiHttpClient.ts index bdf82f0..01262eb 100644 --- a/src/commom/paiHttpClient.ts +++ b/src/commom/paiHttpClient.ts @@ -15,13 +15,20 @@ import { processResponse, IPAIResponseProcessor } from './paiResponseProcessor'; */ export class PAIHttpClient { protected static readonly TIMEOUT: number = 10 * 1000; + protected static readonly EXPIRATION: number = 4000; private readonly cluster: IPAICluster; constructor(cluster: IPAICluster) { this.cluster = cluster; } - public async login(username?: string, password?: string): Promise { + /** + * Login by username and password. + * @param username Username, set undefined to use the username in cluster setting. + * @param password Password, set undefined to use the password in cluster setting. + * @param expiration Expiration time in seconds, default 4000s. + */ + public async login(username?: string, password?: string, expiration?: number): Promise { const url: string = Util.fixUrl( `${this.cluster.rest_server_uri}/api/v2/authn/basic/login`, this.cluster.https @@ -30,7 +37,7 @@ export class PAIHttpClient { const res: AxiosResponse = await axios.post( url, querystring.stringify({ - expiration: 4000, + expiration: expiration || PAIHttpClient.EXPIRATION, password: password ? password : this.cluster.password, username: username ? username : this.cluster.username }),