Skip to content

feat: Make the token exchange in pre-authorized-code-flow with a form… #2

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

Open
wants to merge 2 commits into
base: wip/verify
Choose a base branch
from
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
4 changes: 3 additions & 1 deletion src/components/Credentials/CredentialInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const CredentialInfo = ({ credential, mainClassName = "text-sm lg:text-base w-fu
const { isOnline } = useContext(StatusContext);
const [parsedCredential, setParsedCredential] = useState(null);
const [credentialFormat, setCredentialFormat] = useState('');
const [issuerName, setIssuerName] = useState('');
const [credentialSubjectRows, setCredentialSubjectRows] = useState([]);
const container = useContext(ContainerContext);
const { api } = useContext(SessionContext);
Expand All @@ -84,6 +85,7 @@ const CredentialInfo = ({ credential, mainClassName = "text-sm lg:text-base w-fu
}

setParsedCredential(c.beautifiedForm);
setIssuerName(c.beautifiedForm.issuer?.name || '');

let iss = c.beautifiedForm.iss;

Expand Down Expand Up @@ -212,7 +214,7 @@ const CredentialInfo = ({ credential, mainClassName = "text-sm lg:text-base w-fu
{!credentialSubjectRows.some(row => row.name === 'institution') && renderRow('institution', 'Institution', parsedCredential?.vc?.credentialSubject?.institution, screenType)}
{!credentialSubjectRows.some(row => row.name === 'valid_from') && renderRow('valid_from', 'Valid from', parsedCredential?.vc?.credentialSubject?.valid_from, screenType)}
{!credentialSubjectRows.some(row => row.name === 'valid_until') && renderRow('valid_until', 'Valid until', parsedCredential?.vc?.credentialSubject?.valid_until, screenType)}
{!credentialSubjectRows.some(row => row.name === 'issuer') && renderRow('issuer', 'Issuer', parsedCredential?.vc?.credentialSubject?.issuer, screenType)}
{!credentialSubjectRows.some(row => row.name === 'issuer') && renderRow('issuer', 'Issuer', parsedCredential?.vc?.credentialSubject?.issuer || issuerName, screenType)}
</>
)
}
Expand Down
1 change: 1 addition & 0 deletions src/context/ContainerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export const ContainerContextProvider = ({ children }) => {

if (isOpenBadgeCredential) return beautifiedForm.credentialSubject.achievement.name;
if (t.includes('SupportCredential') || t.includes('ExamEnrollmentCredential')) return beautifiedForm.credentialSubject.title;
if (t.includes('AcademicEnrollmentCredential')) return beautifiedForm.credentialSubject.name;
if (storedCredentialConfigurationId === 'EduID') return 'eduID'

return result.beautifiedForm.name || credentialConfiguration?.display?.[0]?.name || 'Credential';
Expand Down
14 changes: 8 additions & 6 deletions src/lib/services/pre-authorized-code-flow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ export const getToken = async (
preAuthorizedCode: string,
pin: string = '',
): Promise<TokenResponse> => {
const bodyFormEncoded = new URLSearchParams({
grant_type: FIELD_PRE_AUTHORIZED_CODE_GRANT_TYPE,
'pre-authorized_code': preAuthorizedCode,
user_pin: pin || undefined,
}).toString();

const response = await ProxyClient.post(
`${credentialIssuer}${PATH_TOKEN}`,
bodyFormEncoded,
{
grant_type: FIELD_PRE_AUTHORIZED_CODE_GRANT_TYPE,
'pre-authorized_code': preAuthorizedCode,
user_pin: pin || undefined,
},
{
'Content-Type': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
},
) as ProxyResponseData;

Expand Down