-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Injiweb 1203] get the authorization server endpoint from its well-known endpoint #229
Open
PuBHARGAVI
wants to merge
9
commits into
mosip:develop
Choose a base branch
from
tw-mosip:injiweb-1203-get-auth-endpoint-from-wellknown
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8e5035b
[INJIWEB-1203] fetch authorization endpoint from authorization wellkn…
PuBHARGAVI 4ef68d9
[INJIWEB-1203] show error screen if auth server doesn't support the r…
PuBHARGAVI 0beb2b5
[INJIWEB-1203] add translations for grant type not supported error sc…
PuBHARGAVI c5e2ee5
[INJIWEB-1203] show service not available toaster if the internet is …
PuBHARGAVI 5811870
[INJIWEB-1203] fix the test cases and update the snapshots
PuBHARGAVI 5127a12
Merge remote-tracking branch 'upstream/develop' into injiweb-1203-get…
PuBHARGAVI bf6a6cd
[INJIWEB-1203] rename proxyServerHost to mimotoHost as mimoto allows …
PuBHARGAVI f96feba
[INJIWEB-1203] update talisman file
PuBHARGAVI 7704023
[INJIWEB-1203] remove redundant crypto library mocking in some test f…
PuBHARGAVI File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ describe('Testing API Class', () => { | |
}); | ||
|
||
test('Check mimotoHost property', () => { | ||
expect(apiModule.api.mimotoHost).toBe('https://api.collab.mossip.net/v1/mimoto'); | ||
expect(apiModule.api.proxyServerHost).toBe('https://api.collab.mossip.net/v1/mimoto'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @PuBHARGAVI we dont have now proxy server. is this still hold true? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed this back to mimotoHost |
||
}); | ||
|
||
test('Check authorizationRedirectionUrl property', () => { | ||
|
@@ -152,7 +152,13 @@ describe('Testing API Class', () => { | |
codeVerifier: 'verifier123' | ||
}; | ||
|
||
const url = apiModule.api.authorization(currentIssuer, credentialWellknown, filterCredentialWellknown, state, code_challenge); | ||
const url = apiModule.api.authorization( | ||
currentIssuer, | ||
filterCredentialWellknown, | ||
state, | ||
code_challenge, | ||
'http://auth.server/authorize' | ||
); | ||
expect(url).toBe( | ||
'http://auth.server/authorize' + | ||
'?response_type=code&' + | ||
|
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 |
---|---|---|
@@ -1,47 +1,137 @@ | ||
import React, {useState} from "react"; | ||
import React, {useEffect, useState} from "react"; | ||
import {getObjectForCurrentLanguage} from "../../utils/i18n"; | ||
import {ItemBox} from "../Common/ItemBox"; | ||
import {generateCodeChallenge, generateRandomString} from "../../utils/misc"; | ||
import {addNewSession} from "../../utils/sessions"; | ||
import {useSelector} from "react-redux"; | ||
import {api} from "../../utils/api"; | ||
import {CredentialProps} from "../../types/components"; | ||
import {CodeChallengeObject, CredentialConfigurationObject} from "../../types/data"; | ||
import { | ||
AuthServerWellknownObject, | ||
CredentialConfigurationObject | ||
} from "../../types/data"; | ||
import {RootState} from "../../types/redux"; | ||
import {DataShareExpiryModal} from "../../modals/DataShareExpiryModal"; | ||
import {useTranslation} from "react-i18next"; | ||
import {RequestStatus, useFetch} from "../../hooks/useFetch"; | ||
|
||
export const Credential: React.FC<CredentialProps> = (props) => { | ||
const {t} = useTranslation("CredentialsPage"); | ||
const {state, response, fetchRequest} = useFetch(); | ||
const selectedIssuer = useSelector((state: RootState) => state.issuers); | ||
const [credentialExpiry, setCredentialExpiry] = useState<boolean>(false); | ||
const language = useSelector((state: RootState) => state.common.language); | ||
const filteredCredentialConfig: CredentialConfigurationObject = props.credentialWellknown.credential_configurations_supported[props.credentialId]; | ||
const credentialObject = getObjectForCurrentLanguage(filteredCredentialConfig.display, language); | ||
const vcStorageExpiryLimitInTimes = useSelector((state: RootState) => state.common.vcStorageExpiryLimitInTimes); | ||
const filteredCredentialConfig: CredentialConfigurationObject = | ||
props.credentialWellknown.credential_configurations_supported[ | ||
props.credentialId | ||
]; | ||
const credentialObject = getObjectForCurrentLanguage( | ||
filteredCredentialConfig.display, | ||
language | ||
); | ||
const vcStorageExpiryLimitInTimes = useSelector( | ||
(state: RootState) => state.common.vcStorageExpiryLimitInTimes | ||
); | ||
const [authorizationReqState, setAuthorizationRequestState] = useState(""); | ||
const [codeChallenge, setCodeChallenge] = useState({ | ||
codeChallenge: "", | ||
codeVerifier: "" | ||
}); | ||
|
||
const onSuccess = (defaultVCStorageExpiryLimit: number = vcStorageExpiryLimitInTimes) => { | ||
useEffect(() => { | ||
if (state === RequestStatus.ERROR) { | ||
props.setToastError(t("errorContent")); | ||
} | ||
if (response) { | ||
if (state === RequestStatus.DONE) { | ||
if (validateIfAuthServerSupportRequiredGrantTypes(response)) { | ||
window.open( | ||
api.authorization( | ||
selectedIssuer.selected_issuer, | ||
filteredCredentialConfig, | ||
authorizationReqState, | ||
codeChallenge, | ||
response["authorization_endpoint"] | ||
), | ||
"_self", | ||
"noopener" | ||
); | ||
} else { | ||
props.setErrorObj({ | ||
code: "errors.authorizationGrantTypeNotSupportedByWallet.code", | ||
message: | ||
"errors.authorizationGrantTypeNotSupportedByWallet.message" | ||
}); | ||
} | ||
} | ||
} | ||
}, [response, state]); | ||
|
||
const onSuccess = async ( | ||
defaultVCStorageExpiryLimit: number = vcStorageExpiryLimitInTimes | ||
) => { | ||
const state = generateRandomString(); | ||
const code_challenge: CodeChallengeObject = generateCodeChallenge(state); | ||
addNewSession({ | ||
setAuthorizationRequestState(state); | ||
setCodeChallenge(generateCodeChallenge(state)); | ||
setCredentialExpiry(false); | ||
|
||
addNewSession({ | ||
selectedIssuer: selectedIssuer.selected_issuer, | ||
certificateId: props.credentialId, | ||
codeVerifier: state, | ||
vcStorageExpiryLimitInTimes: isNaN(defaultVCStorageExpiryLimit) ? vcStorageExpiryLimitInTimes : defaultVCStorageExpiryLimit, | ||
state: state, | ||
vcStorageExpiryLimitInTimes: isNaN(defaultVCStorageExpiryLimit) | ||
? vcStorageExpiryLimitInTimes | ||
: defaultVCStorageExpiryLimit, | ||
state: state | ||
}); | ||
window.open(api.authorization(selectedIssuer.selected_issuer, props.credentialWellknown, filteredCredentialConfig, state, code_challenge), '_self', 'noopener'); | ||
} | ||
|
||
return <React.Fragment> | ||
<ItemBox index={props.index} | ||
url={credentialObject.logo.url} | ||
title={credentialObject.name} | ||
onClick={() => {selectedIssuer.selected_issuer.qr_code_type === 'OnlineSharing' ? setCredentialExpiry(true) : onSuccess(-1)} } /> | ||
{ credentialExpiry && | ||
<DataShareExpiryModal onCancel={() => setCredentialExpiry(false)} | ||
onSuccess={onSuccess} | ||
credentialName={credentialObject.name} | ||
credentialLogo={credentialObject.logo.url}/> | ||
} | ||
</React.Fragment> | ||
} | ||
const apiRequest = api.fetchAuthorizationServerWellknown( | ||
props.credentialWellknown.authorization_servers[0] | ||
); | ||
|
||
await fetchRequest( | ||
apiRequest.url(), | ||
apiRequest.methodType, | ||
apiRequest.headers() | ||
); | ||
}; | ||
|
||
const validateIfAuthServerSupportRequiredGrantTypes = ( | ||
authorizationServerWellknown: AuthServerWellknownObject | ||
) => { | ||
const supportedGrantTypes = ["authorization_code"]; | ||
let authorizationServerGrantTypes = ["authorization_code", "implicit"]; | ||
|
||
if ("grant_types_supported" in authorizationServerWellknown) { | ||
authorizationServerGrantTypes = | ||
authorizationServerWellknown["grant_types_supported"]; | ||
} | ||
|
||
return authorizationServerGrantTypes.some((grantType: string) => | ||
supportedGrantTypes.includes(grantType) | ||
); | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<ItemBox | ||
index={props.index} | ||
url={credentialObject.logo.url} | ||
title={credentialObject.name} | ||
onClick={() => { | ||
selectedIssuer.selected_issuer.qr_code_type === | ||
"OnlineSharing" | ||
? setCredentialExpiry(true) | ||
: onSuccess(-1); | ||
}} | ||
/> | ||
{credentialExpiry && ( | ||
<DataShareExpiryModal | ||
onCancel={() => setCredentialExpiry(false)} | ||
onSuccess={onSuccess} | ||
credentialName={credentialObject.name} | ||
credentialLogo={credentialObject.logo.url} | ||
/> | ||
)} | ||
</React.Fragment> | ||
); | ||
}; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this folder from your local now.