/** * Swagger Petstore - OpenAPI 3.0Lib * * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ). */ import { isExpired, isValid } from './authentication.js'; import { OauthToken } from './models/oauthToken.js'; import { OauthScopePetstoreAuth } from './models/oauthScopePetstoreAuth.js'; export class PetstoreAuthManager { private _oauthClientId: string; private _oauthRedirectUri: string; private _oauthScopes?: OauthScopePetstoreAuth[]; private _oauthClockSkew?: number; private _baseUri: string; constructor( { oauthClientId, oauthRedirectUri, oauthScopes, oauthClockSkew, }: { oauthClientId: string; oauthRedirectUri: string; oauthScopes?: OauthScopePetstoreAuth[]; oauthClockSkew?: number; }, baseUri: string ) { this._oauthClientId = oauthClientId; this._oauthRedirectUri = oauthRedirectUri; this._oauthScopes = oauthScopes; this._oauthClockSkew = oauthClockSkew; this._baseUri = baseUri; } public buildAuthorizationUrl( state: string, additionalParams?: Record ): string { let query = this._baseUri + '/authorize'; const queryParams: Record = { response_type: 'code', client_id: this._oauthClientId, redirect_uri: this._oauthRedirectUri, scope: this._oauthScopes?.join(' '), state: state, ...additionalParams, }; const queryString: string[] = []; for (const key of Object.keys(queryParams)) { const value = queryParams[key]; if (value !== undefined && value !== null) { queryString.push( `${encodeURIComponent(key)}=${encodeURIComponent(value)}` ); } } return (query += (query.indexOf('?') === -1 ? '?' : '&') + queryString.join('&')); } public isValid(oAuthToken: OauthToken | undefined): oAuthToken is OauthToken { return isValid(oAuthToken); } public isExpired(oAuthToken: OauthToken) { return isExpired(oAuthToken, this._oauthClockSkew); } }