@pyrocancode/react-native-vk-auth 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +302 -0
  3. package/android/build.gradle +155 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/java/com/vkauth/VkAuthModule.kt +72 -0
  7. package/android/src/main/java/com/vkauth/VkAuthPackage.kt +23 -0
  8. package/android/src/main/java/com/vkauth/vkid/AuthDelegate.kt +123 -0
  9. package/android/src/main/java/com/vkauth/vkid/InitDelegate.kt +13 -0
  10. package/android/src/main/java/com/vkauth/vkid/JSSilentTokenExchanger.kt +33 -0
  11. package/android/src/main/java/com/vkauth/vkid/SuperAppKitInitUtils.kt +75 -0
  12. package/android/src/main/java/com/vkauth/vkid/dto/AcessToken.kt +19 -0
  13. package/android/src/main/java/com/vkauth/vkid/dto/DtoExt.kt +24 -0
  14. package/android/src/main/java/com/vkauth/vkid/dto/SilentAuthInfo.kt +22 -0
  15. package/android/src/main/java/com/vkauth/vkid/dto/Token.kt +15 -0
  16. package/android/src/main/java/com/vkauth/vkid/dto/UserSession.kt +28 -0
  17. package/android/src/main/java/com/vkauth/vkid/jsinput/App.kt +17 -0
  18. package/android/src/main/java/com/vkauth/vkid/jsinput/Credentials.kt +17 -0
  19. package/android/src/main/java/com/vkauth/vkid/jsinput/Links.kt +19 -0
  20. package/android/src/main/java/com/vkauth/vkid/jsinput/Mode.kt +13 -0
  21. package/android/src/main/java/com/vkauth/vkid/jsinput/VKID.kt +21 -0
  22. package/android/src/main/java/com/vkauth/vkid/jstutils/JsCbSender.kt +16 -0
  23. package/android/src/main/java/com/vkauth/vkid/jstutils/JsOutputParam.kt +7 -0
  24. package/android/src/main/java/com/vkauth/vkid/onetapbutton/OneTapButtonManager.kt +169 -0
  25. package/android/src/main/res/drawable/ic_launcher.xml +2 -0
  26. package/android/src/main/res/values/strings.xml +5 -0
  27. package/ios/Event.swift +70 -0
  28. package/ios/RCTDomain.swift +26 -0
  29. package/ios/VkAuth-Bridging-Header.h +3 -0
  30. package/ios/VkAuth.m +60 -0
  31. package/ios/VkAuth.swift +180 -0
  32. package/ios/VkAuth.xcodeproj/project.pbxproj +315 -0
  33. package/package.json +128 -0
  34. package/react-native-vk-auth.podspec +35 -0
  35. package/src/index.tsx +331 -0
package/package.json ADDED
@@ -0,0 +1,128 @@
1
+ {
2
+ "name": "@pyrocancode/react-native-vk-auth",
3
+ "version": "0.4.1",
4
+ "description": "React Native VK ID Auth (fork of @devsomersets/react-native-vk-auth)",
5
+ "main": "src/index.tsx",
6
+ "module": "src/index.tsx",
7
+ "types": "src/index.tsx",
8
+ "react-native": "src/index.tsx",
9
+ "source": "src/index.tsx",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "*.podspec",
17
+ "!lib/typescript/example",
18
+ "!ios/build",
19
+ "!android/build",
20
+ "!android/gradle",
21
+ "!android/gradlew",
22
+ "!android/gradlew.bat",
23
+ "!android/local.properties",
24
+ "!**/__tests__",
25
+ "!**/__fixtures__",
26
+ "!**/__mocks__",
27
+ "!**/.*"
28
+ ],
29
+ "keywords": [
30
+ "react-native",
31
+ "ios",
32
+ "android"
33
+ ],
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "https://github.com/pyrocancode/react-native-vk-auth.git"
37
+ },
38
+ "author": "Nikita Likhachev <facelessmay@gmail.com> (https://github.com/somersets)",
39
+ "contributors": [
40
+ "pyrocancode (https://github.com/pyrocancode)"
41
+ ],
42
+ "license": "MIT",
43
+ "bugs": {
44
+ "url": "https://github.com/pyrocancode/react-native-vk-auth/issues"
45
+ },
46
+ "homepage": "https://github.com/pyrocancode/react-native-vk-auth#readme",
47
+ "publishConfig": {
48
+ "access": "public"
49
+ },
50
+ "devDependencies": {},
51
+ "peerDependencies": {
52
+ "react": "*",
53
+ "react-native": "*"
54
+ },
55
+ "jest": {
56
+ "preset": "react-native",
57
+ "modulePathIgnorePatterns": [
58
+ "<rootDir>/example/node_modules",
59
+ "<rootDir>/lib/"
60
+ ]
61
+ },
62
+ "commitlint": {
63
+ "extends": [
64
+ "@commitlint/config-conventional"
65
+ ]
66
+ },
67
+ "release-it": {
68
+ "git": {
69
+ "commitMessage": "chore: release ${version}",
70
+ "tagName": "v${version}"
71
+ },
72
+ "npm": {
73
+ "publish": true
74
+ },
75
+ "github": {
76
+ "release": true
77
+ },
78
+ "plugins": {
79
+ "@release-it/conventional-changelog": {
80
+ "preset": "angular"
81
+ }
82
+ }
83
+ },
84
+ "eslintConfig": {
85
+ "root": true,
86
+ "extends": [
87
+ "@react-native-community",
88
+ "prettier"
89
+ ],
90
+ "rules": {
91
+ "prettier/prettier": [
92
+ "error",
93
+ {
94
+ "quoteProps": "consistent",
95
+ "singleQuote": true,
96
+ "tabWidth": 2,
97
+ "trailingComma": "es5",
98
+ "useTabs": false
99
+ }
100
+ ]
101
+ }
102
+ },
103
+ "eslintIgnore": [
104
+ "node_modules/",
105
+ "lib/"
106
+ ],
107
+ "prettier": {
108
+ "quoteProps": "consistent",
109
+ "singleQuote": true,
110
+ "tabWidth": 2,
111
+ "trailingComma": "es5",
112
+ "useTabs": false
113
+ },
114
+ "react-native-builder-bob": {
115
+ "source": "src",
116
+ "output": "lib",
117
+ "targets": [
118
+ "commonjs",
119
+ "module",
120
+ [
121
+ "typescript",
122
+ {
123
+ "project": "tsconfig.build.json"
124
+ }
125
+ ]
126
+ ]
127
+ }
128
+ }
@@ -0,0 +1,35 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "react-native-vk-auth"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+ s.platforms = { :ios => "11.4" }
14
+ s.source = { :git => "https://github.com/pyrocancode/react-native-vk-auth.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
17
+
18
+ s.dependency "React-Core"
19
+ s.dependency "VK-SDK"
20
+
21
+ # Don't install the dependencies when we run `pod install` in the old architecture.
22
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
23
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
24
+ s.pod_target_xcconfig = {
25
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
26
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
27
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
28
+ }
29
+ s.dependency "React-Codegen"
30
+ s.dependency "RCT-Folly"
31
+ s.dependency "RCTRequired"
32
+ s.dependency "RCTTypeSafety"
33
+ s.dependency "ReactCommon/turbomodule/core"
34
+ end
35
+ end
package/src/index.tsx ADDED
@@ -0,0 +1,331 @@
1
+ import React from 'react';
2
+ import {
3
+ NativeModules,
4
+ Platform,
5
+ ImageResolvedAssetSource,
6
+ NativeEventEmitter,
7
+ requireNativeComponent,
8
+ ViewProps,
9
+ NativeModule,
10
+ } from 'react-native';
11
+
12
+ const LINKING_ERROR =
13
+ `The package 'react-native-vk-auth' doesn't seem to be linked. Make sure: \n\n` +
14
+ Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
15
+ '- You rebuilt the app after installing the package\n' +
16
+ '- You are not using Expo Go\n';
17
+
18
+ interface VkAuthModule extends NativeModule {
19
+ getUserProfile: () => Promise<VKID.UserProfile>;
20
+ startAuth: () => void;
21
+ closeAuth: () => void;
22
+ logout: () => void;
23
+ getUserSessions: () => void;
24
+ initialize: (app: VK.App, vkid: VKID) => void;
25
+ openURL: (url: string) => void;
26
+
27
+ accessTokenChangedSuccess: (token: string, userId: bigint) => void;
28
+ accessTokenChangedFailed: (error: Error) => void;
29
+ }
30
+
31
+ const VkAuth: VkAuthModule = NativeModules.VkAuth
32
+ ? NativeModules.VkAuth
33
+ : new Proxy(
34
+ {},
35
+ {
36
+ get() {
37
+ throw new Error(LINKING_ERROR);
38
+ },
39
+ }
40
+ );
41
+
42
+ export class VK {
43
+ static initialize(app: VK.App, vkid: VKID) {
44
+ VkAuth.initialize(app, vkid);
45
+ }
46
+
47
+ static openURL(url: string) {
48
+ VkAuth.openURL(url);
49
+ }
50
+ }
51
+
52
+ export namespace VK {
53
+ export interface App {
54
+ mode: Mode;
55
+ credentials: Credentials;
56
+ }
57
+
58
+ export enum Mode {
59
+ DEBUG = 'DEBUG',
60
+ TEST = 'TEST',
61
+ RELEASE = 'RELEASE',
62
+ }
63
+
64
+ export interface Credentials {
65
+ clientId: string;
66
+ clientSecret: string;
67
+ }
68
+ }
69
+
70
+ export class VKID {
71
+ readonly appName: string;
72
+ readonly appVersion: string;
73
+ readonly appIcon: ImageResolvedAssetSource;
74
+ readonly appLinks: VKID.Links;
75
+ private readonly silentTokenExchanger: VKID.SilentTokenExchanger;
76
+ private readonly eventEmitter: NativeEventEmitter;
77
+
78
+ constructor(
79
+ appName: string,
80
+ appVersion: string,
81
+ appIcon: ImageResolvedAssetSource,
82
+ appLinks: VKID.Links,
83
+ silentTokenExchanger: VKID.SilentTokenExchanger
84
+ ) {
85
+ this.appName = appName;
86
+ this.appVersion = appVersion;
87
+ this.appIcon = appIcon;
88
+ this.appLinks = appLinks;
89
+ this.silentTokenExchanger = silentTokenExchanger;
90
+ this.eventEmitter = new NativeEventEmitter(VkAuth);
91
+
92
+ this.initSilentDataReceive();
93
+ }
94
+
95
+ private initSilentDataReceive() {
96
+ this.eventEmitter.removeAllListeners('onSilentDataReceive');
97
+ this.eventEmitter.addListener(
98
+ 'onSilentDataReceive',
99
+ async (silentToken: VKID.SilentToken) => {
100
+ let exchangeResult: VKID.TokenExchangeResult =
101
+ await this.silentTokenExchanger.exchange(silentToken).catch(() => {
102
+ return { ok: false, error: Error('Exchange failed') };
103
+ });
104
+ VKID.accessTokenChanged(exchangeResult);
105
+ }
106
+ );
107
+ }
108
+
109
+ startAuth() {
110
+ VkAuth.startAuth();
111
+ }
112
+
113
+ closeAuth() {
114
+ VkAuth.closeAuth();
115
+ }
116
+
117
+ async getUserProfile(): Promise<VKID.UserProfile> {
118
+ return await VkAuth.getUserProfile();
119
+ }
120
+
121
+ logout() {
122
+ VkAuth.logout();
123
+ }
124
+
125
+ userSessions(): Promise<Array<VKID.Session.UserSession>> {
126
+ // @ts-ignore
127
+ let promise: Promise<Array<UserSessionInternal.UserSession>> =
128
+ VkAuth.getUserSessions();
129
+ return promise.then((sessions) => {
130
+ return sessions.map((session) => {
131
+ console.log(session);
132
+ return session.type === UserSessionInternal.Type.AUTHORIZED
133
+ ? new VKID.Session.Authorized()
134
+ : new VKID.Session.Authenticated();
135
+ });
136
+ });
137
+ }
138
+
139
+ setOnAuthChanged(onAuthChanged: VKID.AuthChangedCallback) {
140
+ this.eventEmitter.removeAllListeners('onLogout');
141
+ this.eventEmitter.removeAllListeners('onAuth');
142
+
143
+ this.eventEmitter.addListener('onLogout', () => {
144
+ onAuthChanged.onLogout();
145
+ });
146
+ this.eventEmitter.addListener(
147
+ 'onAuth',
148
+ (session: UserSessionInternal.UserSession) => {
149
+ console.log(session);
150
+ let externalSession =
151
+ session.type === UserSessionInternal.Type.AUTHORIZED
152
+ ? new VKID.Session.Authorized()
153
+ : new VKID.Session.Authenticated();
154
+ onAuthChanged.onAuth(externalSession);
155
+ }
156
+ );
157
+ }
158
+
159
+ private static accessTokenChanged(
160
+ result: VKID.TokenExchangeResult<VKID.AccessToken, Error>
161
+ ) {
162
+ if (result.ok) {
163
+ VkAuth.accessTokenChangedSuccess(
164
+ result.accessToken.token.value,
165
+ result.accessToken.userID.value
166
+ );
167
+ } else {
168
+ VkAuth.accessTokenChangedFailed(result.error);
169
+ }
170
+ }
171
+ }
172
+
173
+ export namespace VKID {
174
+ export class Token {
175
+ value: string;
176
+
177
+ constructor(value: string) {
178
+ this.value = value;
179
+ }
180
+ }
181
+
182
+ export class UserID {
183
+ value: bigint;
184
+
185
+ constructor(value: bigint) {
186
+ this.value = value;
187
+ }
188
+ }
189
+
190
+ export interface SilentToken {
191
+ token: Token;
192
+ uuid: string;
193
+ firstName: string;
194
+ lastName: string;
195
+ }
196
+
197
+ export interface SilentTokenExchanger {
198
+ exchange(
199
+ silentData: VKID.SilentToken
200
+ ): Promise<VKID.TokenExchangeResult<VKID.AccessToken, Error>>;
201
+ }
202
+
203
+ export interface AccessToken {
204
+ token: Token;
205
+ userID: UserID;
206
+ }
207
+
208
+ export interface Links {
209
+ serviceUserAgreement: string;
210
+ servicePrivacyPolicy: string;
211
+ serviceSupport: string | null;
212
+ }
213
+
214
+ export interface UserProfile {
215
+ userID: UserID;
216
+ firstName: string | null;
217
+ lastName: string | null;
218
+ phone: string | null;
219
+ photo200: string | null;
220
+ email: string | null;
221
+ userHash: string | null;
222
+ }
223
+
224
+ export interface AuthChangedCallback {
225
+ onAuth(userSession: VKID.Session.UserSession): void;
226
+
227
+ onLogout(): void;
228
+ }
229
+
230
+ export namespace Session {
231
+ export abstract class UserSession {}
232
+
233
+ export class Authorized extends UserSession {
234
+ constructor() {
235
+ super();
236
+ }
237
+
238
+ get userProfile(): Promise<VKID.UserProfile> {
239
+ return VkAuth.getUserProfile();
240
+ }
241
+
242
+ toString(): string {
243
+ return 'Authorized';
244
+ }
245
+ }
246
+
247
+ export class Authenticated extends UserSession {
248
+ toString(): string {
249
+ return 'Authenticated';
250
+ }
251
+ }
252
+ }
253
+
254
+ export type TokenExchangeResult<T = VKID.AccessToken, E = Error> =
255
+ | { ok: true; accessToken: T }
256
+ | { ok: false; error: E };
257
+ }
258
+
259
+ namespace UserSessionInternal {
260
+ export class UserSession {
261
+ private readonly _type: UserSessionInternal.Type;
262
+
263
+ constructor(type: Type) {
264
+ this._type = type;
265
+ }
266
+
267
+ get type(): Type {
268
+ return this._type;
269
+ }
270
+ }
271
+
272
+ export enum Type {
273
+ AUTHORIZED = 'authorized',
274
+ AUTHENTICATED = 'authenticated',
275
+ }
276
+ }
277
+
278
+ export namespace VKOneTapButtonSpace {
279
+ export const nativeView = requireNativeComponent('RTCVkOneTapButton');
280
+
281
+ export enum BgColor {
282
+ BLUE = 'BLUE',
283
+ WHITE = 'WHITE',
284
+ CUSTOM = 'CUSTOM',
285
+ }
286
+
287
+ export interface BgStyle {
288
+ style: BgColor;
289
+ customVkIconColor?: string;
290
+ customBackgroundColor?: string;
291
+ customTextColor?: string;
292
+ }
293
+
294
+ export enum IconGravity {
295
+ START = 'START',
296
+ TEXT = 'TEXT',
297
+ }
298
+
299
+ export enum LineFieldType {
300
+ ACTION = 'ACTION',
301
+ PHONE = 'PHONE',
302
+ NONE = 'NONE',
303
+ }
304
+
305
+ export interface Texts {
306
+ noUserText?: string;
307
+ actionText?: string;
308
+ phoneText?: string;
309
+ }
310
+
311
+ export type Props = {
312
+ backgroundStyle?: BgStyle | undefined;
313
+ iconGravity?: IconGravity | undefined;
314
+ firstLineFieldType?: LineFieldType | undefined;
315
+ secondLineFieldType?: LineFieldType | undefined;
316
+ oneLineTextSize?: number | undefined;
317
+ firstLineTextSize?: number | undefined;
318
+ secondLineTextSize?: number | undefined;
319
+ avatarSize?: number | undefined;
320
+ iconSize?: number | undefined;
321
+ progressSize?: number | undefined;
322
+ texts?: Texts | undefined;
323
+ } & ViewProps;
324
+ }
325
+
326
+ export class VKOneTapButton extends React.Component<VKOneTapButtonSpace.Props> {
327
+ render() {
328
+ // @ts-ignore
329
+ return <VKOneTapButtonSpace.nativeView {...this.props} />;
330
+ }
331
+ }