Change localhost to public URI
This commit is contained in:
parent
f746412af6
commit
cd163bd79c
75
src/views/AuthLogin.vue
Normal file
75
src/views/AuthLogin.vue
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import * as oauth2 from 'oauth4webapi'
|
||||||
|
|
||||||
|
const issuer = new URL("https://sso.gitgals.com/application/o/sebtest/.well-known/openid-configuration");
|
||||||
|
const as = await oauth2
|
||||||
|
.discoveryRequest(issuer, {algorithm: "oauth2"})
|
||||||
|
.then((response) => oauth2.processDiscoveryResponse(issuer, response))
|
||||||
|
|
||||||
|
const client: oauth2.Client = {
|
||||||
|
client_id: 'CLaLr8sikEiN7NCrPMhjhbtLZgnZJ6JZVzPdVN5P',
|
||||||
|
token_endpoint_auth_method: "none",
|
||||||
|
};
|
||||||
|
|
||||||
|
const redirect_uri = "http://localhost:5173/";
|
||||||
|
|
||||||
|
if (as.code_challenge_methods_supported?.includes('S256') !== true) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
|
||||||
|
const code_verifier = oauth2.generateRandomCodeVerifier();
|
||||||
|
const code_challenge = await oauth2.calculatePKCECodeChallenge(code_verifier);
|
||||||
|
const code_challenge_method = "S256";
|
||||||
|
|
||||||
|
{
|
||||||
|
// Redirect user to auth endpoint
|
||||||
|
const authorizationUrl = new URL(as.authorization_endpoint!);
|
||||||
|
authorizationUrl.searchParams.set('client_id', client.client_id);
|
||||||
|
authorizationUrl.searchParams.set('code_challenge', code_challenge);
|
||||||
|
authorizationUrl.searchParams.set('code_challenge_method', code_challenge_method);
|
||||||
|
authorizationUrl.searchParams.set('redirect_uri', redirect_uri);
|
||||||
|
authorizationUrl.searchParams.set('response_type', 'code');
|
||||||
|
authorizationUrl.searchParams.set('scope', 'api:read');
|
||||||
|
}
|
||||||
|
|
||||||
|
// User lands back on redirect URI
|
||||||
|
|
||||||
|
// @ts-expect-error
|
||||||
|
const currentUrl: URL = getCurrentUrl();
|
||||||
|
const parameters = oauth2.validateAuthResponse(as, client, currentUrl, oauth2.expectNoState)
|
||||||
|
if (oauth2.isOAuth2Error(parameters)) {
|
||||||
|
console.log('error', parameters)
|
||||||
|
throw new Error() // Handle OAuth 2.0 redirect error
|
||||||
|
|
||||||
|
const response = await oauth2.authorizationCodeGrantRequest(
|
||||||
|
as,
|
||||||
|
client,
|
||||||
|
parameters,
|
||||||
|
redirect_uri,
|
||||||
|
code_verifier,
|
||||||
|
)
|
||||||
|
|
||||||
|
let challenges: oauth2.WWWAuthenticateChallenge[] | undefined
|
||||||
|
if ((challenges = oauth2.parseWwwAuthenticateChallenges(response))) {
|
||||||
|
for (const challenge of challenges) {
|
||||||
|
console.log('challenge', challenge)
|
||||||
|
}
|
||||||
|
throw new Error() // Handle www-authenticate challenges as needed
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await oauth2.processAuthorizationCodeOAuth2Response(as, client, response)
|
||||||
|
if (oauth2.isOAuth2Error(result)) {
|
||||||
|
console.log('error', result)
|
||||||
|
throw new Error() // Handle OAuth 2.0 response body error
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('result', result)
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="signin">
|
||||||
|
<h1>Signin page</h1>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@ -27,7 +27,7 @@ import router from '@/router';
|
|||||||
lastName: member.value.lastName,
|
lastName: member.value.lastName,
|
||||||
email: member.value.email
|
email: member.value.email
|
||||||
};
|
};
|
||||||
const url = "http://127.0.0.1:8000/member";
|
const url = "https://api.gitgals.com/member";
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
|
|||||||
@ -50,7 +50,7 @@
|
|||||||
lastName: member.value.lastName,
|
lastName: member.value.lastName,
|
||||||
email: member.value.email
|
email: member.value.email
|
||||||
};
|
};
|
||||||
const url = "http://127.0.0.1:8000/member/" + id;
|
const url = "https://api.gitgals.com/member/" + id;
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
method: 'put',
|
method: 'put',
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get("http://127.0.0.1:8000/members");
|
const response = await axios.get("https://api.gitgals.com/members");
|
||||||
users.value = response.data.members;
|
users.value = response.data.members;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching data: ", error);
|
console.error("Error fetching data: ", error);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user