From 49e0622f1a19bc8524d029572ebe182e458decd2 Mon Sep 17 00:00:00 2001 From: Alexey Tayanovsky Date: Sat, 22 Jan 2022 23:34:07 +0300 Subject: [PATCH 1/8] renamed vk provider file extension to .ts --- src/providers/{vk.js => vk.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/providers/{vk.js => vk.ts} (100%) diff --git a/src/providers/vk.js b/src/providers/vk.ts similarity index 100% rename from src/providers/vk.js rename to src/providers/vk.ts From 0eb914636207763250614d80b9462d377946e9f1 Mon Sep 17 00:00:00 2001 From: Alexey Tayanovsky Date: Sat, 22 Jan 2022 23:35:40 +0300 Subject: [PATCH 2/8] lint issue fix --- app/pages/api/auth/[...nextauth].ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pages/api/auth/[...nextauth].ts b/app/pages/api/auth/[...nextauth].ts index 6c97c06b9c..d5070d5b54 100644 --- a/app/pages/api/auth/[...nextauth].ts +++ b/app/pages/api/auth/[...nextauth].ts @@ -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" From 049cca98340b122f7c7fd3a31dc1d69f4256ab7d Mon Sep 17 00:00:00 2001 From: Alexey Tayanovsky Date: Sat, 22 Jan 2022 23:36:45 +0300 Subject: [PATCH 3/8] vk provider fix --- app/pages/api/auth/[...nextauth].ts | 7 ++++- src/next/index.ts | 2 +- src/providers/vk.ts | 40 +++++++++++++++++++++++++---- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/app/pages/api/auth/[...nextauth].ts b/app/pages/api/auth/[...nextauth].ts index d5070d5b54..f37197868f 100644 --- a/app/pages/api/auth/[...nextauth].ts +++ b/app/pages/api/auth/[...nextauth].ts @@ -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" @@ -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, diff --git a/src/next/index.ts b/src/next/index.ts index bc0794adb6..1452df4764 100644 --- a/src/next/index.ts +++ b/src/next/index.ts @@ -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] diff --git a/src/providers/vk.ts b/src/providers/vk.ts index 8530e1e4b8..c2a74c24be 100644 --- a/src/providers/vk.ts +++ b/src/providers/vk.ts @@ -1,5 +1,19 @@ -/** @type {import(".").OAuthProvider} */ -export default function VK(options) { +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 + }> +} + +export default function VK< + P extends Record = VkProfile + >(options: OAuthUserConfig

): OAuthConfig

{ const apiVersion = "5.126" // https://vk.com/dev/versions return { @@ -7,14 +21,30 @@ export default function VK(options) { name: "VK", type: "oauth", authorization: `https://oauth.vk.com/authorize?scope=email&v=${apiVersion}`, - token: `https://oauth.vk.com/access_token?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, + }, + } + ) + return { tokens: response } + }, + }, userinfo: `https://api.vk.com/method/users.get?fields=photo_100&v=${apiVersion}`, - profile(result) { + profile(result: P) { const profile = result.response?.[0] ?? {} return { id: profile.id, name: [profile.first_name, profile.last_name].filter(Boolean).join(" "), - email: profile.email, + email: null, image: profile.photo_100, } }, From c7a91f4f21b8673224371803b2551ff1350d7366 Mon Sep 17 00:00:00 2001 From: Alexey Tayanovsky Date: Sat, 22 Jan 2022 23:41:08 +0300 Subject: [PATCH 4/8] formatting fix --- src/providers/vk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/vk.ts b/src/providers/vk.ts index c2a74c24be..d0603ca885 100644 --- a/src/providers/vk.ts +++ b/src/providers/vk.ts @@ -13,7 +13,7 @@ export interface VkProfile { export default function VK< P extends Record = VkProfile - >(options: OAuthUserConfig

): OAuthConfig

{ +>(options: OAuthUserConfig

): OAuthConfig

{ const apiVersion = "5.126" // https://vk.com/dev/versions return { From ac93e1ee326e6598cfddef9c5579c6616ae6b411 Mon Sep 17 00:00:00 2001 From: Alexey Tayanovsky Date: Sun, 23 Jan 2022 18:36:03 +0300 Subject: [PATCH 5/8] remove user_id from tokens --- src/providers/vk.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/providers/vk.ts b/src/providers/vk.ts index d0603ca885..d8347a118a 100644 --- a/src/providers/vk.ts +++ b/src/providers/vk.ts @@ -35,7 +35,8 @@ export default function VK< }, } ) - return { tokens: response } + const { user_id, ...tokens } = response + return { tokens } }, }, userinfo: `https://api.vk.com/method/users.get?fields=photo_100&v=${apiVersion}`, From 11fa68e00fa48eaa0217d6f405b28669faa80b39 Mon Sep 17 00:00:00 2001 From: Aliaksei Tayanouski Date: Fri, 4 Feb 2022 21:52:11 +0300 Subject: [PATCH 6/8] Update src/providers/vk.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Balázs Orbán --- src/providers/vk.ts | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/src/providers/vk.ts b/src/providers/vk.ts index d8347a118a..70089b1560 100644 --- a/src/providers/vk.ts +++ b/src/providers/vk.ts @@ -21,24 +21,10 @@ export default function 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 } - }, + client: { + token_endpoint_auth_method: "client_secret_post", }, + token: `https://oauth.vk.com/access_token?v=${apiVersion}`, userinfo: `https://api.vk.com/method/users.get?fields=photo_100&v=${apiVersion}`, profile(result: P) { const profile = result.response?.[0] ?? {} From 7dc959daac015f7729e3d1a4e07b384fef72d1ea Mon Sep 17 00:00:00 2001 From: Aliaksei Tayanouski Date: Fri, 4 Feb 2022 21:53:07 +0300 Subject: [PATCH 7/8] Update src/providers/vk.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Balázs Orbán --- src/providers/vk.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/providers/vk.ts b/src/providers/vk.ts index 70089b1560..bc6546bddc 100644 --- a/src/providers/vk.ts +++ b/src/providers/vk.ts @@ -14,7 +14,7 @@ export interface VkProfile { export default function VK< P extends Record = VkProfile >(options: OAuthUserConfig

): OAuthConfig

{ - const apiVersion = "5.126" // https://vk.com/dev/versions + const apiVersion = "5.131" // https://vk.com/dev/versions return { id: "vk", From 05ef0965fc586fd89e308d8f7241e8c86a099191 Mon Sep 17 00:00:00 2001 From: Alexey Tayanovsky Date: Fri, 4 Feb 2022 23:39:12 +0300 Subject: [PATCH 8/8] user interface additions --- packages/next-auth/src/providers/vk.ts | 245 +++++++++++++++++++++++++ 1 file changed, 245 insertions(+) diff --git a/packages/next-auth/src/providers/vk.ts b/packages/next-auth/src/providers/vk.ts index bc6546bddc..6f8cdc740e 100644 --- a/packages/next-auth/src/providers/vk.ts +++ b/packages/next-auth/src/providers/vk.ts @@ -1,6 +1,7 @@ import type { OAuthConfig, OAuthUserConfig } from "." export interface VkProfile { + // https://dev.vk.com/reference/objects/user response: Array<{ id: number first_name: string @@ -8,6 +9,250 @@ export interface VkProfile { photo_100: string can_access_closed: boolean is_closed: boolean + deactivated?: string + sex?: 0 | 1 | 2 + screen_name?: string + photo_50?: string + online?: 0 | 1 + online_mobile?: 0 | 1 + online_app?: number + verified?: 0 | 1 + trending?: 0 | 1 + friend_status?: 0 | 1 | 2 | 3 + first_name_nom?: string + first_name_gen?: string + first_name_dat?: string + first_name_acc?: string + first_name_ins?: string + first_name_abl?: string + last_name_nom?: string + last_name_gen?: string + last_name_dat?: string + last_name_acc?: string + last_name_ins?: string + last_name_abl?: string + nickname?: string + maiden_name?: string + domain?: string + bdate?: string + city?: { + id: number + title: string + } + country?: { + id: number + title: string + } + timezone?: number + photo_200?: string + photo_max?: string + photo_200_orig?: string + photo_400_orig?: string + photo_max_orig?: string + photo_id?: string + has_photo?: 0 | 1 + has_mobile?: 0 | 1 + is_friend?: 0 | 1 + can_post?: 0 | 1 + can_see_all_posts?: 0 | 1 + can_see_audio?: 0 | 1 + connections?: { + facebook?: string + skype?: string + twitter?: string + livejournal?: string + instagram?: string + } + photo_400?: string + wall_default?: 'owner' | 'all' + interests?: string + books?: string + tv?: string + quotes?: string + about?: string + games?: string + movies?: string + activities?: string + music?: string + can_write_private_message?: 0 | 1 + can_send_friend_request?: 0 | 1 + contacts?: { + mobile_phone?: string + home_phone?: string + } + site?: string + status_audio?: { + access_key?: string + artist: string + id: number + owner_id: number + title: string + url?: string + duration: number + date?: number + album_id?: number + genre_id?: number + performer?: string + } + status?: string + last_seen?: { + platform?: 1 | 2 | 3 | 4 | 5 | 6 | 7 + time?: number + } + exports?: { + facebook?: number + livejournal?: number + twitter?: number + instagram?: number + } + crop_photo?: { + photo: { + access_key?: string + album_id: number + date: number + height?: number + id: number + images?: Array<{ + height?: number + type?: 's' | 'm' | 'x' | 'l' | 'o' | 'p' | 'q' | 'r' | 'y' | 'z' | 'w' + url?: string + width?: number + }> + lat?: number + long?: number + owner_id: number + photo_256?: string + can_comment?: 0 | 1 + place?: string + post_id?: number + sizes?: Array<{ + height: number + url: string + src?: string + type: 's' | 'm' | 'x' | 'o' | 'p' | 'q' | 'r' | 'k' | 'l' | 'y' | 'z' | 'c' | 'w' | 'a' | 'b' | 'e' | 'i' | 'd' | 'j' | 'temp' | 'h' | 'g' | 'n' | 'f' | 'max' + width: number + }> + text?: string + user_id?: number + width?: number + has_tags: boolean + } + crop: { + x: number + y: number + x2: number + y2: number + } + rect: { + x: number + y: number + x2: number + y2: number + } + } + followers_count?: number + blacklisted?: 0 | 1 + blacklisted_by_me?: 0 | 1 + is_favorite?: 0 | 1 + is_hidden_from_feed?: 0 | 1 + common_count?: number + occupation?: { + id?: number + name?: string + type?: 'work' | 'school' | 'university' + } + career?: { + group_id?: number + company?: string + country_id?: number + city_id?: number + city_name?: string + from?: number + until?: number + position?: string + } + military?: { + country_id: number + from?: number + unit: string + unit_id: number + until?: number + } + education?: { + university?: number + university_name?: string + faculty?: number + faculty_name?: string + graduation?: number + } + home_town?: string + relation?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 + relation_partner?: { + deactivated?: string + first_name: string + hidden?: number + id: number + last_name: string + can_access_closed?: boolean + is_closed?: boolean + } + personal?: { + alcohol?: 1 | 2 | 3 | 4 | 5 + inspired_by?: string + langs?: string[] + life_main?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 + people_main?: 1 | 2 | 3 | 4 | 5 | 6 + political?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 + religion?: string + smoking?: 1 | 2 | 3 | 4 | 5 + } + universities?: Array<{ + chair?: number + chair_name?: string + city?: number + country?: number + education_form?: string + education_status?: string + faculty?: number + faculty_name?: string + graduation?: number + id?: number + name?: string + university_group_id?: number + }> + schools?: Array<{ + city?: number + class?: string + country?: number + id?: string + name?: string + type?: number + type_str?: string + year_from?: number + year_graduated?: number + year_to?: number + speciality?: string + }> + relatives?: Array<{ + id?: number + name?: string + type: 'parent' | 'child' | 'grandparent' | 'grandchild' | 'sibling' + }> + counters?: { + albums?: number + videos?: number + audios?: number + photos?: number + notes?: number + friends?: number + groups?: number + online_friends?: number + mutual_friends?: number + user_videos?: number + followers?: number + pages?: number + } + is_no_index?: 0 | 1 }> }