Skip to content
Merged
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,29 @@ Enables OAuth2-based authentication for an adminforth application.
- Support external identity providers for sign-in.
- Reduce friction in authentication workflows.
- Integrate provider-based auth into the admin panel.
- Start OAuth flow directly from an external page via `?start_oauth=<provider>` query parameter.

## Documentation

Full setup and configuration guide:

[AdminForth OAuth Documentation](https://adminforth.dev/docs/tutorial/Plugins/oauth/)

## Starting OAuth flow from an external page

If you have an external website with a "Sign in with Google" button that should open the AdminForth OAuth flow directly — without showing the login form first — use the `start_oauth` query parameter:

```
https://your-admin.example.com/login?start_oauth=google
https://your-admin.example.com/login?start_oauth=clerk
```

The value must match the provider name (case-insensitive). AdminForth will immediately redirect the user to the OAuth provider, skipping the login page entirely.

**Supported values** depend on the providers configured in your plugin setup. The name is derived from the adapter class name — for example `AdminForthAdapterOauth2Google` → `google`, `AdminForthAdapterOauth2Clerk` → `clerk`.

If the specified provider is not found, an error message is shown on the login page. If `start_oauth` is provided without a value (`?start_oauth`), nothing happens and the regular login form is displayed.

## About AdminForth

AdminForth is an open-source, agent-first admin framework for building robust admin panels and back-office applications faster.
Expand Down
29 changes: 29 additions & 0 deletions custom/OAuthLoginButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@
</template>

<script setup>
import { onMounted } from 'vue';
import { useRoute } from 'vue-router';
import { useAdminforth } from '@/adminforth';
import { useI18n } from 'vue-i18n';

const props = defineProps({
meta: {
type: Object,
required: true
}
});

const route = useRoute();
const { alert } = useAdminforth();
const { t } = useI18n();

const getProviderName = (provider) => {
return provider.replace('AdminForthAdapter', '').replace('Oauth2', '');
};
Expand All @@ -40,4 +49,24 @@ const handleLogin = (authUrl) => {
url.searchParams.set('redirect_uri', redirectUri);
return url.toString();
};

function tryStartOAuth(query) {
if (!('start_oauth' in query)) return;

const provider = props.meta.providers.find(({ provider }) =>
getProviderName(provider).toLowerCase() === query.start_oauth.toLowerCase()
);

if (provider) {
window.location.href = handleLogin(provider.authUrl);
} else if (query.start_oauth === '') {
alert({ variant: 'warning', message: t('Empty OAuth provider') });
} else {
alert({ variant: 'warning', message: t('Unknown OAuth provider: {provider}', { provider: query.start_oauth }) });
}
}

onMounted(() => {
tryStartOAuth(route.query);
});
</script>