0

I need to reliably get the access token from this string:

final authString = "myApp:%23access_token=abcd1234asdf1qwerty&scope=channel_feed_read&token_type=bearer"

I've decoded it Uri.decodeComponent(authString) but then I'm not sure how to get the auth token from the URL fragment.

Thanks

1 Answers1

3

You can replace that # with ? after decoding and parse query parameters as a normal Uri.

final link = 'myApp:%23access_token=abcd1234asdf1qwerty&scope=channel_feed_read&token_type=bearer';

final decoded = Uri.decodeFull(link).replaceAll('#', '?');
final uri = Uri.parse(decoded);

final access_token = uri.queryParameters['access_token'];
final token_type = uri.queryParameters['token_type']
final scope = uri.queryParameters['scope'];
Frenco
  • 1,299
  • 1
  • 8
  • 25