-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(authentication-service): added idp server controller for login an…
…d discovery endpoint BREAKING CHANGE:
- Loading branch information
1 parent
1131668
commit 74b87f6
Showing
14 changed files
with
592 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
services/authentication-service/src/modules/auth/controllers/identity-server.controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import {inject} from '@loopback/core'; | ||
import {get, getModelSchemaRef, post, requestBody} from '@loopback/rest'; | ||
import { | ||
CONTENT_TYPE, | ||
ErrorCodes, | ||
OPERATION_SECURITY_SPEC, | ||
STATUS_CODE, | ||
X_TS_TYPE, | ||
} from '@sourceloop/core'; | ||
import {authenticateClient, STRATEGY} from 'loopback4-authentication'; | ||
import {authorize} from 'loopback4-authorization'; | ||
import {IdpLoginService} from '../../../services'; | ||
import { | ||
IdpAuthMethod, | ||
IdpAuthRequest, | ||
IdpConfiguration, | ||
TokenResponse, | ||
} from '../models'; | ||
|
||
export class IdentityServerController { | ||
constructor( | ||
@inject('services.IdpLoginService') | ||
private readonly idpLoginHelperService: IdpLoginService, | ||
) {} | ||
|
||
@authenticateClient(STRATEGY.CLIENT_PASSWORD) | ||
@authorize({permissions: ['*']}) | ||
@post('/connect/auth', { | ||
description: 'POST Call for idp login', | ||
responses: { | ||
[STATUS_CODE.OK]: { | ||
description: 'Token Response', | ||
content: { | ||
[CONTENT_TYPE.JSON]: { | ||
schema: {[X_TS_TYPE]: TokenResponse}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
async connectAuth( | ||
@requestBody({ | ||
content: { | ||
[CONTENT_TYPE.FORM_URLENCODED]: { | ||
schema: getModelSchemaRef(IdpAuthRequest), | ||
}, | ||
}, | ||
}) | ||
idpAuthRequest: IdpAuthRequest, | ||
): Promise<void> { | ||
switch (idpAuthRequest?.auth_method) { | ||
case IdpAuthMethod.COGNITO: | ||
await this.idpLoginHelperService.loginViaCognito(); | ||
break; | ||
case IdpAuthMethod.GOOGLE: | ||
await this.idpLoginHelperService.loginViaGoogle(); | ||
break; | ||
case IdpAuthMethod.SAML: | ||
await this.idpLoginHelperService.loginViaSaml(); | ||
break; | ||
case IdpAuthMethod.FACEBOOK: | ||
await this.idpLoginHelperService.loginViaFacebook(); | ||
break; | ||
case IdpAuthMethod.APPLE: | ||
await this.idpLoginHelperService.loginViaApple(); | ||
break; | ||
case IdpAuthMethod.AZURE: | ||
await this.idpLoginHelperService.loginViaAzure(); | ||
break; | ||
case IdpAuthMethod.INSTAGRAM: | ||
await this.idpLoginHelperService.loginViaInstagram(); | ||
break; | ||
case IdpAuthMethod.KEYCLOAK: | ||
await this.idpLoginHelperService.loginViaKeycloak(); | ||
break; | ||
} | ||
} | ||
|
||
@authorize({permissions: ['*']}) | ||
@get('/.well-known/openid-configuration', { | ||
security: OPERATION_SECURITY_SPEC, | ||
description: 'To get the openid configuration', | ||
responses: { | ||
[STATUS_CODE.OK]: { | ||
description: 'OpenId Configuration', | ||
content: { | ||
[CONTENT_TYPE.JSON]: IdpConfiguration, | ||
}, | ||
}, | ||
...ErrorCodes, | ||
}, | ||
}) | ||
async me(): Promise<void> { | ||
this.idpLoginHelperService.getOpenIdConfiguration(); | ||
} | ||
} |
Oops, something went wrong.