Innim / flutter_login_vk

Flutter Plugin to login via VK.com
BSD 3-Clause "New" or "Revised" License
18 stars 20 forks source link

Error: Vk auth is invalid for this user #17

Closed gadgetreviews closed 2 years ago

gadgetreviews commented 2 years ago

Hello, I am using flutter_login_vk with parse server. Several weeks ago similar code (with 1.0.0 version of flutter_login_vk) and similar configuration was working fine. Now I am getting this error when I try to login. I noticed that latest Android SDK version for vk is 3.4.0 but plugin uses 3.2.2 version. Is this the reason that I am getting this error?

final ParseResponse response = await ParseUser.loginWith(
        "vkontakte", authData,
      );

I get following error:

I/flutter ( 9656): ╭-- Parse Response
I/flutter ( 9656): Class: _User
I/flutter ( 9656): Function: ParseApiRQ.loginWith
I/flutter ( 9656): Status Code: 101
I/flutter ( 9656): Type: ObjectNotFound
I/flutter ( 9656): Error: Vk auth is invalid for this user.
I/flutter ( 9656): ╰-- 
greymag commented 2 years ago

Hello.

I noticed that latest Android SDK version for vk is 3.4.0 but plugin uses 3.2.2 version. Is this the reason that I am getting this error?

I don't think so.

I'm not sure when you got this error. Could you try minimal example with only plugin methods call and see what error do you get?

gadgetreviews commented 2 years ago

void vkLogin() async {
    vk = VKLogin();
    await vk.initSdk();
    final res = await vk.logIn(scope: [
      VKScope.email,
      VKScope.photos,
    ]);
    if (! res.isError) {
      print("LoginView: vkLogin not error");
      final loginResult = res.asValue!.value;
      if (! loginResult.isCanceled) {
        print("LoginView: vkLogin not cancelled");
        var accessToken = loginResult.accessToken;
        vkAccessToken = accessToken!.token;
        vkUserId = accessToken.userId;
        await vkLoginWithToken();
      } else {
        print("Login cancelled");
      }
    } else {
      print("Login failed");
    }
}

Future<void> vkLoginWithToken() async {
    print("LoginView: vkLoginWithToken");
    if (vkAccessToken == null) return;
    if (await vk.isLoggedIn) {
      email = await vk.getUserEmail();
      var profile1 = await vk.getUserProfile();
      var profile = await profile1.asFuture;
      firstName =  profile!.firstName;
      lastName =  profile.lastName;
      pictureUrl = profile.photo200!;
      // Login to parse with vk
      var authData = {
        "id": vkUserId!,
        "access_token": vkAccessToken!
      };
/////////////
// I get error here
// response.success is false
////////////
      final ParseResponse response = await ParseUser.loginWith(
        "vkontakte", authData,
      );
      if (response.success) {
        // User is logged in, test with ParseUser.currentUser()
        currentUser = await ParseUser.currentUser();
      } else {
        print("Login failed");
      }
    } else {
      print("Unexpected error");
    }
}
gadgetreviews commented 2 years ago

Same project was working fine with flutter_login_vk version 1.0.0 several weeks ago. Now 1.0.0 is not working anymore either.

I get this log from parse server when ParseUser.loginWith executed:

I/flutter ( 9656): ╭-- Parse Response
I/flutter ( 9656): Class: _User
I/flutter ( 9656): Function: ParseApiRQ.loginWith
I/flutter ( 9656): Status Code: 101
I/flutter ( 9656): Type: ObjectNotFound
I/flutter ( 9656): Error: Vk auth is invalid for this user.
I/flutter ( 9656): ╰-- 
greymag commented 2 years ago

Now I get it =)

Looks like accessToken is correct, because you can load profile information with VKLogin.getUserProfile(). This and the fact that version 1.0.0 was working and now it doesn't, suggests that there are some problem with ParseUser.loginWith or VK changed something.

If you can trace requests to VK from Parse Server and responses, that might be provide some useful information.

gadgetreviews commented 2 years ago

I reported this issue at parse server too. I was not sure if it is related to parse server or flutter_login_vk.

So I tested the same code with iOS simulator and it works at iOS. In this case the problem should not be related to parse server.

Is it possible to related with android sdk 3.2.2? As far as I know 1.0.0 was using android sdk 1.6.7. Android sdk upgraded from 1.6.7 to 3.2.2? And I noticed that 1.0.0 was using ios sdk 1.6.1 and 2.1.0 is using ios sdk 1.6.2.

gadgetreviews commented 2 years ago

This problem occurs only at android devices, and does not occur at iOS devices.

gadgetreviews commented 2 years ago

When I try to use 1.0.0 or 1.0.1 version I get this error. If we can fix this, I maybe use old version to login to vk.

E/flutter ( 4762): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type 'Null' is not a subtype of type 'int' in type cast
E/flutter ( 4762): #0      new VKAccessToken.fromMap (package:flutter_login_vk/src/models/vk_access_token.dart:14:38)
E/flutter ( 4762): #1      new VKLoginResult.fromMap (package:flutter_login_vk/src/models/vk_login_result.dart:18:29)
E/flutter ( 4762): #2      VKLogin.logIn (package:flutter_login_vk/src/vk_login.dart:178:43)
E/flutter ( 4762): <asynchronous suspension>
E/flutter ( 4762): #3      _LoginViewState.vkLogin (login.dart:176:17)
E/flutter ( 4762): <asynchronous suspension>
gadgetreviews commented 2 years ago

I also get this error at var profile = await profile1.asFuture; with v1.0.0 and v1.0.1.

E/flutter ( 7717): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(API_ERROR, Get profile error: null, {apiCode: -101, message: null}, null)
gadgetreviews commented 2 years ago

If you can trace requests to VK from Parse Server and responses, that might be provide some useful information.

Problem still exists. How can I trace requests to VK from Parse Server and responses?

greymag commented 2 years ago

Hey! Can you try version from GitHub, branch 16.android-sdk-3.4? Does it have a problem too?

https://github.com/Innim/flutter_login_vk/tree/feature/16.android-sdk-3.4

gadgetreviews commented 2 years ago

Hey! Can you try version from GitHub, branch 16.android-sdk-3.4? Does it have a problem too?

https://github.com/Innim/flutter_login_vk/tree/feature/16.android-sdk-3.4

I am sorry for late reply. I was busy with another project and I didn't have time to test this branch but I had another feedback from parse-server issue of github. And I think I have a solution for this problem. I don't know if it is a workaround or perfect solution. But I can login with vk now.

As a summary, I added VKScope.offline scope when login to vk. And it seems to working fine now. You may consider to update the documentation for this.

https://github.com/parse-community/parse-server/issues/6936#issuecomment-999413972