Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import { Configuration } from "@goauthentik/api";
- // import {
- // CoreApi,
- // CoreUsersListRequest,
- // PoliciesApi,
- // Policy,
- // PolicyTestRequest,
- // PolicyTestResult,
- // User,
- // } from "@goauthentik/api";
- const basePath = 'http://localhost:9000';
- const clientId = 'EU2Dko0AvWUflP2ZnjQbqINWrUEJMkiINJs5Onxd';
- const clientSecret = 'IUD4ioCmq4wAbNDmZ4Ta8zm6GALUXMNhEelgTOwi1XDUCPjfUvNuwRCN8m7Mad1QHTwDNzbebvoxCrZqPl3Y7OJmBhrwqK2xdBPZAbqQI23KnEBa5ARCW1rKmlkSFbmL';
- const tokenUrl = `${basePath}/application/o/token/`;
- const redirectUri = 'http://localhost:3000';
- const code = '852bc4b4088b41788936f704b3b2c3e9';
- // Endpoint URL
- // Authorization /application/o/authorize/
- // Token /application/o/token/
- // User Info /application/o/userinfo/
- // Token Revoke /application/o/revoke/
- // End Session /application/o/<application slug>/end-session/
- // JWKS /application/o/<application slug>/jwks/
- // OpenID Configuration /application/o/<application slug>/.well-known/openid-configuration
- async function fetchData() {
- try {
- const params = new URLSearchParams();
- params.append('grant_type', 'authorization_code');
- params.append('code', code);
- params.append('redirect_uri', redirectUri);
- params.append('client_id', clientId);
- params.append('client_secret', clientSecret);
- params.append('scope', 'api read_user openid profile email');
- const tokenRes = await fetch(tokenUrl, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- body: params
- });
- if (!tokenRes.ok) {
- const err = await tokenRes.text();
- throw new Error(`Token exchange failed: ${err}`);
- }
- const tokenData = await tokenRes.json();
- console.log(tokenData);
- const accessToken = tokenData.access_token;
- // // Create new config with token
- // const configWithToken = new Configuration({
- // basePath: basePath + '/api/v3',
- // accessToken: accessToken, // ✅ use this instead of setting headers manually
- // });
- const userInfo = await fetch(`${basePath}/application/o/userinfo/`, {
- headers: {
- Authorization: `Bearer ${accessToken}`
- }
- });
- console.log(await userInfo.json());
- } catch (error) {
- console.error('Error:', error);
- }
- }
- fetchData();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement