-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
102 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { getOpenIdConnectUrl } from './utils' |
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,32 @@ | ||
import * as SUT from './utils' | ||
|
||
describe('src/utils', () => { | ||
describe('getOpenIdConnectUrl', () => { | ||
it('should get the open id connect url as expected', () => { | ||
// when ... we want to get the open id connect url from the url search params | ||
// then ... it should get the url as expected | ||
const params = new URLSearchParams() | ||
params.set('client_id', 'CLIENT_ID') | ||
params.set('external_url', 'EXTERNAL_URL') | ||
params.set('login_id', 'LOGIN_ID') | ||
|
||
const result = SUT.getOpenIdConnectUrl(params) | ||
|
||
expect(result).toEqual( | ||
'openid-vc://?client_id=CLIENT_ID&request_uri=EXTERNAL_URL%2Fapi%2FpresentCredential%3Flogin_id%3DLOGIN_ID', | ||
) | ||
}) | ||
|
||
it('should throw an error when not all url params are set', () => { | ||
// when ... we want to get the open id connect url from the url search params | ||
// then ... it should get the url as expected | ||
const params = new URLSearchParams() | ||
params.set('client_id', 'CLIENT_ID') | ||
params.set('external_url', 'EXTERNAL_URL') | ||
|
||
const result = () => SUT.getOpenIdConnectUrl(params) | ||
|
||
expect(result).toThrowError('Missing required parameters') | ||
}) | ||
}) | ||
}) |
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,13 @@ | ||
export const getOpenIdConnectUrl = (urlSearchParams: URLSearchParams) => { | ||
const clientId = urlSearchParams.get('client_id') | ||
const externalUrl = urlSearchParams.get('external_url') | ||
const loginId = urlSearchParams.get('login_id') | ||
|
||
if (!clientId || !externalUrl || !loginId) { | ||
throw new Error('Missing required parameters') | ||
} | ||
|
||
return `openid-vc://?client_id=${clientId}&request_uri=${encodeURIComponent( | ||
externalUrl + '/api/presentCredential?login_id=' + loginId, | ||
)}` | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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