|
| 1 | +import type { OAuthConfig, OAuthUserConfig } from "." |
| 2 | + |
| 3 | +export interface VkProfile { |
| 4 | + // https://dev.vk.com/reference/objects/user |
| 5 | + response: Array<{ |
| 6 | + id: number |
| 7 | + first_name: string |
| 8 | + last_name: string |
| 9 | + photo_100: string |
| 10 | + can_access_closed: boolean |
| 11 | + is_closed: boolean |
| 12 | + deactivated?: string |
| 13 | + sex?: 0 | 1 | 2 |
| 14 | + screen_name?: string |
| 15 | + photo_50?: string |
| 16 | + online?: 0 | 1 |
| 17 | + online_mobile?: 0 | 1 |
| 18 | + online_app?: number |
| 19 | + verified?: 0 | 1 |
| 20 | + trending?: 0 | 1 |
| 21 | + friend_status?: 0 | 1 | 2 | 3 |
| 22 | + first_name_nom?: string |
| 23 | + first_name_gen?: string |
| 24 | + first_name_dat?: string |
| 25 | + first_name_acc?: string |
| 26 | + first_name_ins?: string |
| 27 | + first_name_abl?: string |
| 28 | + last_name_nom?: string |
| 29 | + last_name_gen?: string |
| 30 | + last_name_dat?: string |
| 31 | + last_name_acc?: string |
| 32 | + last_name_ins?: string |
| 33 | + last_name_abl?: string |
| 34 | + nickname?: string |
| 35 | + maiden_name?: string |
| 36 | + domain?: string |
| 37 | + bdate?: string |
| 38 | + city?: { |
| 39 | + id: number |
| 40 | + title: string |
| 41 | + } |
| 42 | + country?: { |
| 43 | + id: number |
| 44 | + title: string |
| 45 | + } |
| 46 | + timezone?: number |
| 47 | + photo_200?: string |
| 48 | + photo_max?: string |
| 49 | + photo_200_orig?: string |
| 50 | + photo_400_orig?: string |
| 51 | + photo_max_orig?: string |
| 52 | + photo_id?: string |
| 53 | + has_photo?: 0 | 1 |
| 54 | + has_mobile?: 0 | 1 |
| 55 | + is_friend?: 0 | 1 |
| 56 | + can_post?: 0 | 1 |
| 57 | + can_see_all_posts?: 0 | 1 |
| 58 | + can_see_audio?: 0 | 1 |
| 59 | + connections?: { |
| 60 | + facebook?: string |
| 61 | + skype?: string |
| 62 | + twitter?: string |
| 63 | + livejournal?: string |
| 64 | + instagram?: string |
| 65 | + } |
| 66 | + photo_400?: string |
| 67 | + wall_default?: 'owner' | 'all' |
| 68 | + interests?: string |
| 69 | + books?: string |
| 70 | + tv?: string |
| 71 | + quotes?: string |
| 72 | + about?: string |
| 73 | + games?: string |
| 74 | + movies?: string |
| 75 | + activities?: string |
| 76 | + music?: string |
| 77 | + can_write_private_message?: 0 | 1 |
| 78 | + can_send_friend_request?: 0 | 1 |
| 79 | + contacts?: { |
| 80 | + mobile_phone?: string |
| 81 | + home_phone?: string |
| 82 | + } |
| 83 | + site?: string |
| 84 | + status_audio?: { |
| 85 | + access_key?: string |
| 86 | + artist: string |
| 87 | + id: number |
| 88 | + owner_id: number |
| 89 | + title: string |
| 90 | + url?: string |
| 91 | + duration: number |
| 92 | + date?: number |
| 93 | + album_id?: number |
| 94 | + genre_id?: number |
| 95 | + performer?: string |
| 96 | + } |
| 97 | + status?: string |
| 98 | + last_seen?: { |
| 99 | + platform?: 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 100 | + time?: number |
| 101 | + } |
| 102 | + exports?: { |
| 103 | + facebook?: number |
| 104 | + livejournal?: number |
| 105 | + twitter?: number |
| 106 | + instagram?: number |
| 107 | + } |
| 108 | + crop_photo?: { |
| 109 | + photo: { |
| 110 | + access_key?: string |
| 111 | + album_id: number |
| 112 | + date: number |
| 113 | + height?: number |
| 114 | + id: number |
| 115 | + images?: Array<{ |
| 116 | + height?: number |
| 117 | + type?: 's' | 'm' | 'x' | 'l' | 'o' | 'p' | 'q' | 'r' | 'y' | 'z' | 'w' |
| 118 | + url?: string |
| 119 | + width?: number |
| 120 | + }> |
| 121 | + lat?: number |
| 122 | + long?: number |
| 123 | + owner_id: number |
| 124 | + photo_256?: string |
| 125 | + can_comment?: 0 | 1 |
| 126 | + place?: string |
| 127 | + post_id?: number |
| 128 | + sizes?: Array<{ |
| 129 | + height: number |
| 130 | + url: string |
| 131 | + src?: string |
| 132 | + 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' |
| 133 | + width: number |
| 134 | + }> |
| 135 | + text?: string |
| 136 | + user_id?: number |
| 137 | + width?: number |
| 138 | + has_tags: boolean |
| 139 | + } |
| 140 | + crop: { |
| 141 | + x: number |
| 142 | + y: number |
| 143 | + x2: number |
| 144 | + y2: number |
| 145 | + } |
| 146 | + rect: { |
| 147 | + x: number |
| 148 | + y: number |
| 149 | + x2: number |
| 150 | + y2: number |
| 151 | + } |
| 152 | + } |
| 153 | + followers_count?: number |
| 154 | + blacklisted?: 0 | 1 |
| 155 | + blacklisted_by_me?: 0 | 1 |
| 156 | + is_favorite?: 0 | 1 |
| 157 | + is_hidden_from_feed?: 0 | 1 |
| 158 | + common_count?: number |
| 159 | + occupation?: { |
| 160 | + id?: number |
| 161 | + name?: string |
| 162 | + type?: 'work' | 'school' | 'university' |
| 163 | + } |
| 164 | + career?: { |
| 165 | + group_id?: number |
| 166 | + company?: string |
| 167 | + country_id?: number |
| 168 | + city_id?: number |
| 169 | + city_name?: string |
| 170 | + from?: number |
| 171 | + until?: number |
| 172 | + position?: string |
| 173 | + } |
| 174 | + military?: { |
| 175 | + country_id: number |
| 176 | + from?: number |
| 177 | + unit: string |
| 178 | + unit_id: number |
| 179 | + until?: number |
| 180 | + } |
| 181 | + education?: { |
| 182 | + university?: number |
| 183 | + university_name?: string |
| 184 | + faculty?: number |
| 185 | + faculty_name?: string |
| 186 | + graduation?: number |
| 187 | + } |
| 188 | + home_town?: string |
| 189 | + relation?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 190 | + relation_partner?: { |
| 191 | + deactivated?: string |
| 192 | + first_name: string |
| 193 | + hidden?: number |
| 194 | + id: number |
| 195 | + last_name: string |
| 196 | + can_access_closed?: boolean |
| 197 | + is_closed?: boolean |
| 198 | + } |
| 199 | + personal?: { |
| 200 | + alcohol?: 1 | 2 | 3 | 4 | 5 |
| 201 | + inspired_by?: string |
| 202 | + langs?: string[] |
| 203 | + life_main?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
| 204 | + people_main?: 1 | 2 | 3 | 4 | 5 | 6 |
| 205 | + political?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 206 | + religion?: string |
| 207 | + smoking?: 1 | 2 | 3 | 4 | 5 |
| 208 | + } |
| 209 | + universities?: Array<{ |
| 210 | + chair?: number |
| 211 | + chair_name?: string |
| 212 | + city?: number |
| 213 | + country?: number |
| 214 | + education_form?: string |
| 215 | + education_status?: string |
| 216 | + faculty?: number |
| 217 | + faculty_name?: string |
| 218 | + graduation?: number |
| 219 | + id?: number |
| 220 | + name?: string |
| 221 | + university_group_id?: number |
| 222 | + }> |
| 223 | + schools?: Array<{ |
| 224 | + city?: number |
| 225 | + class?: string |
| 226 | + country?: number |
| 227 | + id?: string |
| 228 | + name?: string |
| 229 | + type?: number |
| 230 | + type_str?: string |
| 231 | + year_from?: number |
| 232 | + year_graduated?: number |
| 233 | + year_to?: number |
| 234 | + speciality?: string |
| 235 | + }> |
| 236 | + relatives?: Array<{ |
| 237 | + id?: number |
| 238 | + name?: string |
| 239 | + type: 'parent' | 'child' | 'grandparent' | 'grandchild' | 'sibling' |
| 240 | + }> |
| 241 | + counters?: { |
| 242 | + albums?: number |
| 243 | + videos?: number |
| 244 | + audios?: number |
| 245 | + photos?: number |
| 246 | + notes?: number |
| 247 | + friends?: number |
| 248 | + groups?: number |
| 249 | + online_friends?: number |
| 250 | + mutual_friends?: number |
| 251 | + user_videos?: number |
| 252 | + followers?: number |
| 253 | + pages?: number |
| 254 | + } |
| 255 | + is_no_index?: 0 | 1 |
| 256 | + }> |
| 257 | +} |
| 258 | + |
| 259 | +export default function VK< |
| 260 | + P extends Record<string, any> = VkProfile |
| 261 | +>(options: OAuthUserConfig<P>): OAuthConfig<P> { |
| 262 | + const apiVersion = "5.131" // https://vk.com/dev/versions |
| 263 | + |
| 264 | + return { |
| 265 | + id: "vk", |
| 266 | + name: "VK", |
| 267 | + type: "oauth", |
| 268 | + authorization: `https://oauth.vk.com/authorize?scope=email&v=${apiVersion}`, |
| 269 | + client: { |
| 270 | + token_endpoint_auth_method: "client_secret_post", |
| 271 | + }, |
| 272 | + token: `https://oauth.vk.com/access_token?v=${apiVersion}`, |
| 273 | + userinfo: `https://api.vk.com/method/users.get?fields=photo_100&v=${apiVersion}`, |
| 274 | + profile(result: P) { |
| 275 | + const profile = result.response?.[0] ?? {} |
| 276 | + return { |
| 277 | + id: profile.id, |
| 278 | + name: [profile.first_name, profile.last_name].filter(Boolean).join(" "), |
| 279 | + email: null, |
| 280 | + image: profile.photo_100, |
| 281 | + } |
| 282 | + }, |
| 283 | + options, |
| 284 | + } |
| 285 | +} |
0 commit comments