2025-04-25 12:14:51 -05:00
|
|
|
import type { Page } from '@playwright/test';
|
|
|
|
|
|
2025-06-06 03:23:51 -07:00
|
|
|
export async function getUserCode(page: Page, clientId: string, clientSecret: string): Promise<string> {
|
|
|
|
|
return page.request
|
2025-04-25 12:14:51 -05:00
|
|
|
.post('/api/oidc/device/authorize', {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
},
|
|
|
|
|
form: {
|
|
|
|
|
client_id: clientId,
|
|
|
|
|
client_secret: clientSecret,
|
|
|
|
|
scope: 'openid profile email'
|
|
|
|
|
}
|
|
|
|
|
})
|
2025-06-06 03:23:51 -07:00
|
|
|
.then((r) => r.json())
|
|
|
|
|
.then((r) => r.user_code);
|
|
|
|
|
}
|
2025-04-25 12:14:51 -05:00
|
|
|
|
2025-06-06 03:23:51 -07:00
|
|
|
export async function exchangeCode(page: Page, params: Record<string,string>): Promise<{access_token?: string, token_type?: string, expires_in?: number, error?: string}> {
|
|
|
|
|
return page.request
|
|
|
|
|
.post('/api/oidc/token', {
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
|
|
},
|
|
|
|
|
form: params,
|
|
|
|
|
})
|
|
|
|
|
.then((r) => r.json());
|
2025-04-25 12:14:51 -05:00
|
|
|
}
|
|
|
|
|
|
2025-06-06 03:23:51 -07:00
|
|
|
export async function getClientAssertion(page: Page, data: {issuer: string, audience: string, subject: string}): Promise<string> {
|
|
|
|
|
return page.request
|
|
|
|
|
.post('/api/externalidp/sign', {
|
|
|
|
|
data: {
|
|
|
|
|
iss: data.issuer,
|
|
|
|
|
aud: data.audience,
|
|
|
|
|
sub: data.subject,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
.then((r) => r.text());
|
|
|
|
|
}
|