diff --git a/flutter/realm_flutter/tests/pubspec.yaml b/flutter/realm_flutter/tests/pubspec.yaml index fd8c48bcf..2df26dc1e 100644 --- a/flutter/realm_flutter/tests/pubspec.yaml +++ b/flutter/realm_flutter/tests/pubspec.yaml @@ -26,7 +26,6 @@ dev_dependencies: flutter_lints: ^2.0.1 build_runner: ^2.1.2 test: ^1.20.1 - http: ^0.13.4 flutter: uses-material-design: true diff --git a/lib/src/cli/atlas_apps/baas_client.dart b/lib/src/cli/atlas_apps/baas_client.dart index e1b1a3c0f..db9a5cb29 100644 --- a/lib/src/cli/atlas_apps/baas_client.dart +++ b/lib/src/cli/atlas_apps/baas_client.dart @@ -238,6 +238,53 @@ class BaasClient { "field_name": "company" }'''); } + + if (confirmationType == null) { + const facebookSecret = "876750ac6d06618b323dee591602897f"; + final dynamic createFacebookSecretResult = await _post('groups/$_groupId/apps/$appId/secrets', '{"name":"facebookSecret","value":"$facebookSecret"}'); + String facebookClientSecretKeyName = createFacebookSecretResult['name'] as String; + await enableProvider(app, 'oauth2-facebook', config: '''{ + "clientId": "1265617494254819" + }''', secretConfig: '''{ + "clientSecret": "$facebookClientSecretKeyName" + }''', metadataFelds: '''{ + "required": true, + "name": "name" + }, + { + "required": true, + "name": "first_name" + }, + { + "required": true, + "name": "last_name" + }, + { + "required": false, + "name": "email" + }, + { + "required": false, + "name": "gender" + }, + { + "required": false, + "name": "birthday" + }, + { + "required": false, + "name": "min_age" + }, + { + "required": false, + "name": "max_age" + }, + { + "required": false, + "name": "picture" + }'''); + } + print('Creating database db_$name$_appSuffix'); await _createMongoDBService(app, '''{ diff --git a/test/README.md b/test/README.md index c9aff530b..fb91b668a 100644 --- a/test/README.md +++ b/test/README.md @@ -187,3 +187,16 @@ For the purpose of the tests the token could be generated by the following proce ``` * Once you have the token you can use it to login in the tests with `app.login(Credentials.jwt(token))`. Be sure that the public key configured in the cloud apps is from the correct key pair and corresponds to the private key used for generating this token. +## Manually configure Facebook authentication providers + +### Facebook login + +1. Login to https://developers.facebook.com/ with account dart.CI.test@gmail.com +2. Go to facebook app `"DartCI"` +3. Go to [Settings/Basic](https://developers.facebook.com/apps/1265617494254819/settings/basic/) and you will find `App ID` and `App secret` +4. Following [Facebook Authentication Instruction](https://www.mongodb.com/docs/atlas/app-services/authentication/facebook/) you have to enable facebook authentication provider in [cloud-qa](https://cloud-qa.mongodb.com/) app. Then set `Client ID = App ID` and `Client Secret = App secret` +5. Go back to https://developers.facebook.com/ in menu [Roles/Test Users](https://developers.facebook.com/apps/1265617494254819/roles/test-users/) and select `"Get a user access token"` option for one of the test users. +This access token could be used for facebook login tests with `Credentials.facebook(accessToken)`. +This token will expire fast. If you need long term token you can receive it from this request +https://graph.facebook.com/v14.0/oauth/access_token?grant_type=fb_exchange_token&client_id={`Client ID`}&client_secret={`Client Secret`}&fb_exchange_token={copied access token from `"Get a user access token"`} +6. Use the recieved token in the test. It will be available for 3.5 days. diff --git a/test/credentials_test.dart b/test/credentials_test.dart index 66fbdd443..5bc5405f5 100644 --- a/test/credentials_test.dart +++ b/test/credentials_test.dart @@ -448,4 +448,23 @@ Future main([List? args]) async { await app.logIn(credentials); }, throws("crypto/rsa: verification error")); }); + + ///See test/README.md section 'Manually configure Facebook, Google and Apple authentication providers'" + baasTest('Facebook credentials - login', (configuration) async { + final app = App(configuration); + final accessToken = + 'EAARZCEokqpOMBAKoIHgaG6bqY6LLseGHcQjYdoPhv9FdB89mkVZBWQFOmZCuVeuRfIa5cMtQANLpZBUQI0n4qb4TZCZCAI3vXZC9Oud2qRiieQDtXqE4abZBQJorcBMzECVfsDlus7hk63zW3XzuFCZAxF4BCdRZBHXlGXIzaHhFHhY72aU1apX0tC'; + final credentials = Credentials.facebook(accessToken); + final user = await app.logIn(credentials); + expect(user.state, UserState.loggedIn); + expect(user.provider, AuthProviderType.facebook); + expect(user.profile.name, "Open Graph Test User"); + }, skip: "Manual test"); + + baasTest('Facebook credentials - invalid or expired token', (configuration) async { + final app = App(configuration); + final accessToken = 'invalid or expired token'; + final credentials = Credentials.facebook(accessToken); + expect(() async => await app.logIn(credentials), throws("error fetching info from OAuth2 provider")); + }); }