# rn-vk-auth

> React Native plugin for VK SDK Authorization

Latest version **1.0.5** (published 2023-02-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install rn-vk-auth
pnpm add rn-vk-auth
yarn add rn-vk-auth
bun add rn-vk-auth
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2023-02-18 |
| First published | 2023-02-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 1.2 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | master-eugene |
| Maintainers | master_eugene |
| Keywords | react, react-native, vk, vkontakte, sdk, login, authorization |

## Links

- npm: https://www.npmjs.com/package/rn-vk-auth
- Repository: https://github.com/master-eugene/rn-vk-auth
- Homepage: https://github.com/master-eugene/rn-vk-auth#readme
- Issues: https://github.com/master-eugene/rn-vk-auth/issues
- npm.io page: https://npm.io/package/rn-vk-auth

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2023-02-18
- 1.0.4 — 2023-02-12
- 1.0.3 — 2023-02-12
- 1.0.2 — 2023-02-12
- 1.0.1 — 2023-02-10

## README

# React Native VK authorization wrapper

## Installation

```bash
yarn add rn-vk-auth
```

or

```bash
npm install rn-vk-auth --save
```

Then you should configure native parts:

### Android

1. Edit `android/settings.gradle`

   ```gradle
   ...
   include ':rn-vk-auth'
   project(':rn-vk-auth').projectDir = new File(settingsDir, '../node_modules/rn-vk-auth/android')
   ...
   ```

2. Edit `android/app/build.gradle`

   ```gradle
   ...

   dependencies {
       ...
       compile project(':rn-vk-auth')
   }
   ```

3. Edit `android/app/src/main/java/<...>/MainApplication.java`

   ```java
   ...

   import com.mastereugene.vkauth.VKAuthPackage; //<---- import package

   public class MainApplication extends Application implements ReactApplication {
   ...
     @Override
     protected List<ReactPackage> getPackages() {
       return Arrays.<ReactPackage>asList(
           new MainReactPackage(),
           ...
           new VKAuthPackage()//<---- Add package
         );
     }
   ...
   }
   ```

4. In your `AndroidManifest.xml`, add following line inside `<application>` element:

   ```xml
   <activity android:name="com.vk.sdk.VKServiceActivity" android:label="ServiceActivity" android:theme="@style/VK.Transparent" />
   ```

5. Add VK Application ID to resources (`main/res/values/strings.xml`) so the module will initialize with it at startup:
   ```xml
   <integer name="com_vk_sdk_AppId">VK_APP_ID</integer>
   ```
   (In this example, VK_APP_ID should be replaced with your real VK App ID you've got from VK manage panel)

### iOS

1.  Add `rn-vk-auth` to your XCode project.
    To do so, go to `node_modules/rn-vk-auth/ios` directory inside your project and drag `VKAuthorization.xcodeproj` into your XCode project

    Then add library `libRNVkontakteLogin.a` to `Linked Frameworks and Libraries` section.

2.  Add `VKSdkFramework.framework` to embedded binaries.
    This can be done in `Embedded binaries` section of General Tab of your project in XCode.

3.  Add following fragment to your `info.plist`:

    ```xml
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>vk</string>
        <string>vkauthorize</string>
    </array>
    ```

4.  To use authorization via VK App you need to setup a url-schema of your application.
    Open your application settings then select the Info tab. In the URL Types section click the plus sign.
    Enter vk+APP_ID to the **Identifier** and **URL Schemes** fields.

        Alternatively, you can add following to your info.plist:

        ```xml
        <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>CFBundleURLName</key>
                <string>vk1111111</string>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>vk1111111</string>
                </array>
            </dict>
        </array>
        ```

        Here vk1111111 is your real VK App ID you've got from VK App manage panel

5.  In your AppDelegate.m, you need to import VK SDK:

    ```objc
    #import <VKSdkFramework/VKSdkFramework.h>
    ```

    and then add following code (both methods are required):

    ```objc
    //iOS 9 workflow
    - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options {
       [VKSdk processOpenURL:url fromApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]];
       return YES;
    }

    //iOS 8 and lower
    -(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
    {
       [VKSdk processOpenURL:url fromApplication:sourceApplication];
       return YES;
    }
    ```

6.  **(Optional)** You can add your VK Application ID to `info.plist` so the module will initialize with it at startup:

    ```xml
    <key>VK_APP_ID</key>
    <integer>1111111</integer>
    ```

    If you do so, you won't need to call `VKLogin.initialize(vkAppId)` from your JS code.

The last step is to run `pod install`:

```bash
cd ios && pod install
```

## Usage

Import module in your JS code

```js
import VKAuth from 'rn-vk-auth';
```

Initialize VK with your APP ID once somewhere during your app startup(only iOS):

```js
componentDidMount() {
  VKAuth.initialize(1111111);
}
```

Check if user is logged in, perform login and logout:

```js
const isLoggedIn = await VKAuth.isLoggedIn();
const auth = await VKAuth.login(['friends', 'photos', 'email']);
console.log(auth.access_token);
await VKAuth.logout();
```

---
_Source: https://npm.io/package/rn-vk-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
