Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getAccessToken failed with: Authentication went wrong #196

Open
Roman-Dzerkal opened this issue Aug 3, 2023 · 12 comments
Open

getAccessToken failed with: Authentication went wrong #196

Roman-Dzerkal opened this issue Aug 3, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@Roman-Dzerkal
Copy link

Hello! Here is function that requests access token, trigerred by clicking on a button:

Future<void> getAccessToken() async {
    if (!dotenv.isEveryDefined(['CLIENT_ID', 'REDIRECT_URL'])) {
      throw Exception('There are no spotify credentials. Check your .env file');
    }

    final String spotifyClientId = dotenv.get('CLIENT_ID').toString();
    final String spotifyRedirectUri = dotenv.get('REDIRECT_URL').toString();

    try {
      accessToken = await SpotifySdk.getAccessToken(
          clientId: spotifyClientId, redirectUrl: spotifyRedirectUri);
    } catch (exception) {
      log(exception.toString());
    }
  }

After execution this code I get an error:
изображение

Here the android folder structure
изображение

The build.gradle file cointains next code:

configurations.maybeCreate("default")
artifacts.add("default", file('spotify-app-remote-release-0.8.0.aar'))

The settings.gradle file cointains next code:

include ':app'
include ':spotify-app-remote'

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [Version 10.0.17763.4131], locale ru-UA)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.6.4)
[√] Android Studio (version 2022.3)
[√] IntelliJ IDEA Ultimate Edition (version 2023.1)
[√] VS Code (version 1.80.2)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 1 category.

flutter --version

Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f468f3366c (3 weeks ago) • 2023-07-12 15:19:05 -0700
Engine • revision cdbeda788a
Tools • Dart 3.0.6 • DevTools 2.23.1

What do I do wrong?

@Roman-Dzerkal Roman-Dzerkal added the bug Something isn't working label Aug 3, 2023
@TimHoogstrate
Copy link

Dear @Roman-Dzerkal,

You can try to copy and past the url from your log into your browser. It gives an indication of the error. E.g. redirect url or possibly other errors. Those errors can be copied and pasted into google for further help.

Kind regards,

@brim-borium
Copy link
Owner

Hi @Roman-Dzerkal did you try it with the current example ? Also I just released a prerelease Version of the package. Can you give it a try with the example from the new Version (3.0.0-dev.1)?

@Roman-Dzerkal
Copy link
Author

Hi @Roman-Dzerkal did you try it with the current example ? Also I just released a prerelease Version of the package. Can you give it a try with the example from the new Version (3.0.0-dev.1)?

Hello! I didn't try dev1 version. Once i test it i'll notify you

@Roman-Dzerkal
Copy link
Author

@brim-borium hello! Sorry for long answer. Tested the current example and it doesn't work. I get the same error like in issue description

@Roman-Dzerkal
Copy link
Author

Dear @Roman-Dzerkal,

You can try to copy and past the url from your log into your browser. It gives an indication of the error. E.g. redirect url or possibly other errors. Those errors can be copied and pasted into google for further help.

Kind regards,

изображение

@devsideal
Copy link

devsideal commented Nov 15, 2023

  • Just took the clone
  • Change the CLIENT_ID and REDIRECT_URL in env file
  • Run the project
  • Click on "get auth token" button and Got the same error...!
I/flutter ( 5288): │ #0   SpotifySdk._logException (package:spotify_sdk/spotify_sdk.dart:669:15)
I/flutter ( 5288): │ #1   SpotifySdk.getAccessToken (package:spotify_sdk/spotify_sdk.dart:131:7)
I/flutter ( 5288): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 5288): │ ⛔ getAccessToken failed with: Authentication went wrong
I/flutter ( 5288): │ ⛔ AUTHENTICATION_SERVICE_UNAVAILABLE

Needs any other things to run the given example?

@TimHoogstrate
Copy link

@devsideal,

Could this help?

This is clearly a native SDK issue. If you have searched a bit you would have come up with this issue. I suggest you follow it for any suggested solutions.

I have also come across this and just switching to a different client id solved the issue for me. In the majority of the cases (if not all) the error is the result of misconfiguration. Having said that, we can't provide with this level of support here. This is between you and Spotify. The best thing you can do is create a native Android sample app or use the official example app, with your credentials, and once it works then move to the Flutter SDK.

Closing...

Originally posted by @fotiDim in #177 (comment)

@Mohamed-Abdulla
Copy link

I'm having same issue, can someone help?

@haashem
Copy link

haashem commented Jun 4, 2024

Any solution? me too.

@iampawan
Copy link

iampawan commented Jun 7, 2024

Same issue

@banool
Copy link
Collaborator

banool commented Jun 7, 2024

Unfortunately the maintainers don't have a whole lot of time to work on this, but are ofc happy to look at PRs!

@haashem
Copy link

haashem commented Jun 7, 2024

I solved it ✅:

be sure to have added both debug and release fingerprint for Android in the Spotify developer portal:

https://developer.spotify.com/documentation/android/tutorials/application-fingerprints

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants