Skip to content

Commit c0ab8dd

Browse files
committed
feat: remove redirect_uri from adapter settings
1 parent ad4fde2 commit c0ab8dd

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

custom/OAuthCallback.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ onMounted(async () => {
1818
const urlParams = new URLSearchParams(window.location.search);
1919
const code = urlParams.get('code');
2020
const state = urlParams.get('state');
21-
22-
if (code && state) {
21+
const redirectUri = window.location.origin + '/oauth/callback';
22+
if (code && state && redirectUri) {
2323
const encodedCode = encodeURIComponent(code);
2424
const encodedState = encodeURIComponent(state);
25+
const encodedRedirectUri = encodeURIComponent(redirectUri);
2526
const response = await callAdminForthApi({
26-
path: `/oauth/callback?code=${encodedCode}&state=${encodedState}`,
27+
path: `/oauth/callback?code=${encodedCode}&state=${encodedState}&redirect_uri=${encodedRedirectUri}`,
2728
method: 'GET',
2829
});
2930
if (response.allowedLogin) {

custom/OAuthLoginButtons.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<template>
22
<div :class="meta.iconOnly ? 'flex flex-row justify-center items-center gap-3' : 'flex flex-col justify-center items-center gap-2'" >
3-
<button
3+
<a
44
v-for="provider in meta.providers"
55
:key="provider.provider"
6-
@click="handleLogin(provider.authUrl)"
6+
:href="handleLogin(provider.authUrl)"
77
class="border dark:border-gray-400 flex items-center justify-center hover:bg-gray-50 hover:dark:border-gray-300 hover:dark:bg-gray-700"
88
:class="[
99
meta.iconOnly ? 'w-11 h-11 p-0' : 'w-full py-2 px-4',
@@ -12,7 +12,7 @@
1212
>
1313
<div v-html="provider.icon" class="w-6 h-6" :class="meta.iconOnly ? 'mr-0' : 'mr-4'" :alt="getProviderName(provider.provider)" />
1414
<span v-if="!meta.iconOnly" class="font-medium dark:text-white">Continue with {{ getProviderName(provider.provider) }}</span>
15-
</button>
15+
</a>
1616
</div>
1717
</template>
1818

@@ -29,6 +29,9 @@ const getProviderName = (provider) => {
2929
};
3030
3131
const handleLogin = (authUrl) => {
32-
window.location.href = authUrl;
32+
const redirectUri = window.location.origin + '/oauth/callback';
33+
const url = new URL(authUrl);
34+
url.searchParams.set('redirect_uri', redirectUri);
35+
return url.toString();
3336
};
3437
</script>

index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export default class OAuthPlugin extends AdminForthPlugin {
155155
path: '/oauth/callback',
156156
noAuth: true,
157157
handler: async ({ query, response, headers, cookies, requestUrl }) => {
158-
const { code, state } = query;
158+
const { code, state, redirect_uri } = query;
159159
if (!code) {
160160
return { error: 'No authorization code provided' };
161161
}
@@ -173,7 +173,7 @@ export default class OAuthPlugin extends AdminForthPlugin {
173173
return { error: 'Invalid OAuth provider' };
174174
}
175175

176-
const userInfo = await adapter.getTokenFromCode(code);
176+
const userInfo = await adapter.getTokenFromCode(code, redirect_uri);
177177

178178
let user = await this.adminforth.resource(this.resource.resourceId).get([
179179
Filters.EQ(this.options.emailField, userInfo.email)

0 commit comments

Comments
 (0)