Skip to content

Commit

Permalink
feat: add yandex oauth
Browse files Browse the repository at this point in the history
* feat: add yandex oauth

* chore: linting

* update: change FormData to URLSearchParams & add config.emailRequired

* up

* [autofix.ci] apply automated fixes

* chore(release): v0.2.0

* style: add lint script

* style: add lint script

* ci: update lint fix command

* [autofix.ci] apply automated fixes

---------

Co-authored-by: Sébastien Chopin <[email protected]>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Estéban <[email protected]>
  • Loading branch information
4 people authored Jul 23, 2024
1 parent c9c745f commit 22bd974
Show file tree
Hide file tree
Showing 12 changed files with 952 additions and 166 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ It can also be set using environment variables:
- Twitch
- X (Twitter)
- XSUAA
- Yandex

You can add your favorite provider by creating a new file in [src/runtime/server/lib/oauth/](./src/runtime/server/lib/oauth/).

Expand Down
3 changes: 3 additions & 0 deletions playground/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ NUXT_OAUTH_X_CLIENT_SECRET=
NUXT_OAUTH_XSUAA_CLIENT_ID=
NUXT_OAUTH_XSUAA_CLIENT_SECRET=
NUXT_OAUTH_XSUAA_DOMAIN=
# Yandex
NUXT_OAUTH_YANDEX_CLIENT_ID=
NUXT_OAUTH_YANDEX_CLIENT_SECRET=
212 changes: 110 additions & 102 deletions playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,108 +28,116 @@ async function login() {
logging.value = false
}
const providers = computed(() => [
{
label: session.value.user?.google || 'Google',
to: '/auth/google',
disabled: Boolean(user.value?.google),
icon: 'i-simple-icons-google',
},
{
label: session.value.user?.facebook || 'Facebook',
to: '/auth/facebook',
disabled: Boolean(user.value?.facebook),
icon: 'i-simple-icons-facebook',
},
{
label: session.value.user?.github || 'GitHub',
to: '/auth/github',
disabled: Boolean(user.value?.github),
icon: 'i-simple-icons-github',
},
{
label: user.value?.linkedin || 'LinkedIn',
to: '/auth/linkedin',
disabled: Boolean(user.value?.linkedin),
icon: 'i-simple-icons-linkedin',
},
{
label: user.value?.microsoft || 'Microsoft',
to: '/auth/microsoft',
disabled: Boolean(user.value?.microsoft),
icon: 'i-simple-icons-microsoft',
},
{
label: user.value?.cognito || 'Cognito',
to: '/auth/cognito',
disabled: Boolean(user.value?.cognito),
icon: 'i-simple-icons-amazonaws',
},
{
label: user.value?.discord || 'Discord',
to: '/auth/discord',
disabled: Boolean(user.value?.discord),
icon: 'i-simple-icons-discord',
},
{
label: session.value.user?.spotify || 'Spotify',
to: '/auth/spotify',
disabled: Boolean(user.value?.spotify),
icon: 'i-simple-icons-spotify',
},
{
label: session.value.user?.twitch || 'Twitch',
to: '/auth/twitch',
disabled: Boolean(user.value?.twitch),
icon: 'i-simple-icons-twitch',
},
{
label: user.value?.auth0 || 'Auth0',
to: '/auth/auth0',
disabled: Boolean(user.value?.auth0),
icon: 'i-simple-icons-auth0',
},
{
label: user.value?.battledotnet || 'Battle.net',
to: '/auth/battledotnet',
disabled: Boolean(user.value?.battledotnet),
icon: 'i-simple-icons-battledotnet',
},
{
label: user.value?.keycloak || 'Keycloak',
to: '/auth/keycloak',
disabled: Boolean(user.value?.keycloak),
icon: 'i-simple-icons-redhat',
},
{
label: session.value.user?.paypal || 'PayPal',
to: '/auth/paypal',
disabled: Boolean(user.value?.paypal),
icon: 'i-simple-icons-paypal',
},
{
label: user.value?.steam || 'Steam',
to: '/auth/steam',
disabled: Boolean(user.value?.steam),
icon: 'i-simple-icons-steam',
},
{
label: user.value?.x || 'X',
to: '/auth/x',
disabled: Boolean(user.value?.x),
icon: 'i-simple-icons-x',
},
{
label: user.value?.xsuaa || 'XSUAA',
to: '/auth/xsuaa',
disabled: Boolean(user.value?.xsuaa),
icon: 'i-simple-icons-sap',
},
].map(p => ({
...p,
prefetch: false,
external: true,
})))
const providers = computed(() =>
[
{
label: session.value.user?.google || 'Google',
to: '/auth/google',
disabled: Boolean(user.value?.google),
icon: 'i-simple-icons-google',
},
{
label: session.value.user?.facebook || 'Facebook',
to: '/auth/facebook',
disabled: Boolean(user.value?.facebook),
icon: 'i-simple-icons-facebook',
},
{
label: session.value.user?.github || 'GitHub',
to: '/auth/github',
disabled: Boolean(user.value?.github),
icon: 'i-simple-icons-github',
},
{
label: user.value?.linkedin || 'LinkedIn',
to: '/auth/linkedin',
disabled: Boolean(user.value?.linkedin),
icon: 'i-simple-icons-linkedin',
},
{
label: user.value?.microsoft || 'Microsoft',
to: '/auth/microsoft',
disabled: Boolean(user.value?.microsoft),
icon: 'i-simple-icons-microsoft',
},
{
label: user.value?.cognito || 'Cognito',
to: '/auth/cognito',
disabled: Boolean(user.value?.cognito),
icon: 'i-simple-icons-amazonaws',
},
{
label: user.value?.discord || 'Discord',
to: '/auth/discord',
disabled: Boolean(user.value?.discord),
icon: 'i-simple-icons-discord',
},
{
label: session.value.user?.spotify || 'Spotify',
to: '/auth/spotify',
disabled: Boolean(user.value?.spotify),
icon: 'i-simple-icons-spotify',
},
{
label: session.value.user?.twitch || 'Twitch',
to: '/auth/twitch',
disabled: Boolean(user.value?.twitch),
icon: 'i-simple-icons-twitch',
},
{
label: user.value?.auth0 || 'Auth0',
to: '/auth/auth0',
disabled: Boolean(user.value?.auth0),
icon: 'i-simple-icons-auth0',
},
{
label: user.value?.battledotnet || 'Battle.net',
to: '/auth/battledotnet',
disabled: Boolean(user.value?.battledotnet),
icon: 'i-simple-icons-battledotnet',
},
{
label: user.value?.keycloak || 'Keycloak',
to: '/auth/keycloak',
disabled: Boolean(user.value?.keycloak),
icon: 'i-simple-icons-redhat',
},
{
label: session.value.user?.paypal || 'PayPal',
to: '/auth/paypal',
disabled: Boolean(user.value?.paypal),
icon: 'i-simple-icons-paypal',
},
{
label: user.value?.steam || 'Steam',
to: '/auth/steam',
disabled: Boolean(user.value?.steam),
icon: 'i-simple-icons-steam',
},
{
label: user.value?.x || 'X',
to: '/auth/x',
disabled: Boolean(user.value?.x),
icon: 'i-simple-icons-x',
},
{
label: user.value?.xsuaa || 'XSUAA',
to: '/auth/xsuaa',
disabled: Boolean(user.value?.xsuaa),
icon: 'i-simple-icons-sap',
},
{
label: user.value?.yandex || 'Yandex',
to: '/auth/yandex',
disabled: Boolean(user.value?.yandex),
icon: 'i-gravity-ui-logo-yandex',
},
].map(p => ({
...p,
prefetch: false,
external: true,
})),
)
</script>

<template>
Expand Down
1 change: 1 addition & 0 deletions playground/auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare module '#auth-utils' {
steam?: string
x?: string
xsuaa?: string
yandex?: string
}

interface UserSession {
Expand Down
7 changes: 2 additions & 5 deletions playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ export default defineNuxtConfig({
host: '127.0.0.1',
},
extends: ['@nuxt/ui-pro'],
modules: [
'nuxt-auth-utils',
'@nuxt/ui',
],
modules: ['nuxt-auth-utils', '@nuxt/ui'],
auth: {},
ui: {
icons: ['simple-icons'],
icons: ['simple-icons', 'gravity-ui'],
},
devtools: { enabled: true },
imports: {
Expand Down
3 changes: 3 additions & 0 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
"dependencies": {
"nuxt": "^3.12.2",
"nuxt-auth-utils": "latest"
},
"devDependencies": {
"@iconify-json/gravity-ui": "^1.1.4"
}
}
15 changes: 15 additions & 0 deletions playground/server/routes/auth/yandex.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default oauth.yandexEventHandler({
config: {
emailRequired: true,
},
async onSuccess(event, { user }) {
await setUserSession(event, {
user: {
yandex: user.default_email,
},
loggedInAt: Date.now(),
})

return sendRedirect(event, '/')
},
})
Loading

0 comments on commit 22bd974

Please sign in to comment.