Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VK provider fix #3709

Merged
merged 17 commits into from Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/pages/api/auth/[...nextauth].ts
Expand Up @@ -4,7 +4,7 @@ import GitHubProvider from "next-auth/providers/github"
import Auth0Provider from "next-auth/providers/auth0"
import KeycloakProvider from "next-auth/providers/keycloak"
import TwitterProvider, {
TwitterLegacy as TwitterLegacyProvider,
// TwitterLegacy as TwitterLegacyProvider,
} from "next-auth/providers/twitter"
import CredentialsProvider from "next-auth/providers/credentials"
import IDS4Provider from "next-auth/providers/identity-server4"
Expand All @@ -28,6 +28,7 @@ import AzureB2C from "next-auth/providers/azure-ad-b2c"
import OsuProvider from "next-auth/providers/osu"
import AppleProvider from "next-auth/providers/apple"
import PatreonProvider from "next-auth/providers/patreon"
import VkProvider from "next-auth/providers/vk"

// import { PrismaAdapter } from "@next-auth/prisma-adapter"
// import { PrismaClient } from "@prisma/client"
Expand Down Expand Up @@ -189,7 +190,11 @@ export const authOptions: NextAuthOptions = {
PatreonProvider({
clientId: process.env.PATREON_ID,
clientSecret: process.env.PATREON_SECRET,
})
}),
VkProvider({
clientId: process.env.VK_ID,
clientSecret: process.env.VK_SECRET
}),
],
secret: process.env.SECRET,
debug: true,
Expand Down
2 changes: 1 addition & 1 deletion src/next/index.ts
Expand Up @@ -62,7 +62,7 @@ function NextAuth(
options: NextAuthOptions
): any

/** Tha main entry point to next-auth */
/** The main entry point to next-auth */
function NextAuth(
...args:
| [NextAuthOptions]
Expand Down
23 changes: 0 additions & 23 deletions src/providers/vk.js

This file was deleted.

54 changes: 54 additions & 0 deletions src/providers/vk.ts
@@ -0,0 +1,54 @@
import type { OAuthConfig, OAuthUserConfig } from "."

export interface VkProfile {
response: Array<{
id: number
first_name: string
last_name: string
photo_100: string
can_access_closed: boolean
is_closed: boolean
}>
alexTayanovsky marked this conversation as resolved.
Show resolved Hide resolved
}

export default function VK<
P extends Record<string, any> = VkProfile
>(options: OAuthUserConfig<P>): OAuthConfig<P> {
const apiVersion = "5.126" // https://vk.com/dev/versions
alexTayanovsky marked this conversation as resolved.
Show resolved Hide resolved

return {
id: "vk",
name: "VK",
type: "oauth",
authorization: `https://oauth.vk.com/authorize?scope=email&v=${apiVersion}`,
token: {
url: `https://oauth.vk.com/access_token?v=${apiVersion}`,
async request({ client, params, checks, provider }) {
const response = await client.oauthCallback(
provider.callbackUrl,
params,
checks,
{
exchangeBody: {
client_id: options.clientId,
client_secret: options.clientSecret,
},
}
)
const { user_id, ...tokens } = response
return { tokens }
},
},
alexTayanovsky marked this conversation as resolved.
Show resolved Hide resolved
userinfo: `https://api.vk.com/method/users.get?fields=photo_100&v=${apiVersion}`,
profile(result: P) {
const profile = result.response?.[0] ?? {}
return {
id: profile.id,
name: [profile.first_name, profile.last_name].filter(Boolean).join(" "),
email: null,
image: profile.photo_100,
}
},
options,
}
}