Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ describe('SelfHostedLoginProvider', () => {
'extractCodeFromUrl',
'extractErrorFromUrl',
'accessTokenStorageKey',
'getAccountEndpoints',
],
{
self_hosted_base_url: 'https://example.com',
self_hosted_account_endpoints: accountEndpointsMock,
},
);
Expand All @@ -47,13 +47,15 @@ describe('SelfHostedLoginProvider', () => {

describe('getTokenClient', () => {
it('should return a TokenClient instance', () => {
lfLoginServiceMock.getAccountEndpoints.and.returnValue(accountEndpointsMock);
const tokenClient = provider.getTokenClient();
expect(tokenClient).toBeInstanceOf(SelfHostedTokenClient);
});
});

describe('getBaseAuthorizeUrl', () => {
it('should return the base authorize URL when last OAuth authorize URL exist and host name does not include dev and test environments', () => {
lfLoginServiceMock.getAccountEndpoints.and.returnValue(accountEndpointsMock);
const baseAuthorizeUrl = provider.getBaseAuthorizeUrl();
expect(baseAuthorizeUrl).toBe(accountEndpointsMock.oauthAuthorizeUrl);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ export class SelfHostedLoginProvider implements LoginProvider {
) {}

getTokenClient() {
return new SelfHostedTokenClient(
`${this.lfLoginService.self_hosted_base_url}/v2/Repositories/${this.repositoryId}/Token`,
);
const baseUrl =
this.lfLoginService.self_hosted_base_url ?? this.lfLoginService.getAccountEndpoints()?.regionalDomain;
return new SelfHostedTokenClient(`${baseUrl}/v2/Repositories/${this.repositoryId}/Token`);
}

getBaseAuthorizeUrl(): string {
return this.lfLoginService.self_hosted_account_endpoints?.oauthAuthorizeUrl ?? '';
return (
this.lfLoginService.self_hosted_account_endpoints?.oauthAuthorizeUrl ??
this.lfLoginService.getAccountEndpoints()?.oauthAuthorizeUrl ??
''
);
}

storeInLocalStorage(accessTokenCredentials: AuthorizationCredentials, _accountId: string, _regionalDomain: string) {
Expand Down
Loading