nhost / nhost-dart

Nhost Dart & Flutter packages

Home Page:https://nhost.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

oauth_providers_example.dart: example needs to be updated

diegonc opened this issue · comments

The example's comments give wrong instructions regarding the configuration of NHost's OAuth callbacks:

At line 10 it reads:

/// Success redirect URL: `nhost-example://oauth.login.success`.
/// Failure redirect URL: `nhost-example://oauth.login.failure`.

wheareas only one callback URL can be set on GitHub settings and no URL can be set on NHost's GitHub provider configuration.

Also at line 23, the sign in URL is wrong. It should look like:

/// Fill in this value with the backend URL found on your Nhost project page.
const nhostGithubSignInUrl = '$nhostUrl/v1/auth/signin/provider/github';

There also seems to be a mismatch between the expected query parameter name (refresh_token) and the actual parameter name used by NHost callback (refreshToken)

image

EDIT: here is a workaround for now

if (uri.queryParameters.containsKey('refreshToken')) {
  Map<String, String> params = {};
  params.addAll(uri.queryParameters);
  params['refresh_token'] = uri.queryParameters['refreshToken']!;
  client.auth
    .completeOAuthProviderSignIn(uri.replace(queryParameters: params));
} else {
  client.auth.completeOAuthProviderSignIn(uri);
}

Hi,
I have updated all examples ready on this PR #95

We are activity working to improve the SDK. stay tuned.

Hi, thank you very much for your work!

Will this improvements include the migration from the old backend URL discussed in the link below?

nhost/nhost#1319

Yes, I am working on it. I think we will make it in the next major release two.

@diegonc Check this out nhost_sdk: ^4.0.0-dev.8 or this link for supporting subdomain and region.

Unfortunately, using launchUrl with Facebook would block me from authenticating because of Embedded browser security check from Facebook.

Found a workaround to authenticate with OAuth in Flutter though.

  1. Use this package https://pub.dev/packages/oauth_webauth specifically the BaseWebView widget
  2. add initialUrl with '${createNhostServiceEndpoint(subdomain: YOUR_SUBDOMAIN, region: YOUR_REGION, service: 'auth')}/signin/provider/facebook'
  3. add redirectUrls with your callback URL (https://xxxxxx.auth.YOUR_REGION.nhost.run/v1/signin/provider/facebook/callback)

After successful auth, should return with the callback?code=

The example now has updated URLs but still doesn't work because it refers to success/failure callback settings, which do not seem to be supported. Is there an updated suggestion for how to implement?

because it refers to success/failure callback settings

that part is incorrect, there is no success/failure URLs in hasura-auth, instead, if there is an error, the callback url will include an error query arg describing the issue