项目作者: ajaybhatia

项目描述 :
Login service for Google and Facebook accounts using native Google and Facebook SDK for authorization (Specially for React Native)
高级语言: JavaScript
项目地址: git://github.com/ajaybhatia/meteor-accounts-oauth.git
创建时间: 2018-12-01T20:43:38Z
项目社区:https://github.com/ajaybhatia/meteor-accounts-oauth

开源协议:

下载


accounts—oauth

A login handler for clients wishing to use a platform’s native google and facebook sdk for sign on. Removes the requirement of the browser. Use in combination with accounts-google, accounts-facebook or independently.

Configuration

The only change you’ll have to make on the service is when you set your ServiceConfiguration. You’ll have to add a validClientIds array. This is used because the client id may be different between your web app and your other clients (such as an iOS app). Here’s an example:

  1. /*
  2. Settings would look like this
  3. {
  4. "google": {
  5. "client_secret": "MY_WEB_APP_SECRET",
  6. "client_id": "MY_WEB_APP_CLIENT_ID",
  7. "validClientIds": [
  8. "MY_WEB_APP_CLIENT_ID",
  9. "MY_IOS_APP_CLIENT_ID"
  10. ]
  11. },
  12. "facebook": {
  13. "client_secret": "MY_WEB_APP_SECRET",
  14. "client_id": "MY_WEB_APP_CLIENT_ID",
  15. "validClientIds": [
  16. "MY_WEB_APP_CLIENT_ID",
  17. "MY_IOS_APP_CLIENT_ID"
  18. ]
  19. }
  20. }
  21. */
  22. const google_settings = Meteor.settings.google;
  23. const facebook_settings = Meteor.settings.facebook;
  24. if (google_settings) {
  25. ServiceConfiguration.configurations.remove({
  26. service: 'google'
  27. });
  28. ServiceConfiguration.configurations.insert({
  29. service: 'google',
  30. clientId: google_settings.client_id,
  31. secret: google_settings.client_secret,
  32. validClientIds: Meteor.google_settings.google.validClientIds
  33. });
  34. }
  35. if (facebook_settings) {
  36. ServiceConfiguration.configurations.remove({
  37. service: 'facebook'
  38. });
  39. ServiceConfiguration.configurations.insert({
  40. service: 'facebook',
  41. clientId: facebook_settings.client_id,
  42. secret: facebook_settings.client_secret,
  43. validClientIds: Meteor.facebook_settings.google.validClientIds
  44. });
  45. }

Usage from Client

Call the login method from ddp client with the following parameters:

  1. { google: serviceData }
  2. or
  3. { facebook: serviceData }

Where serviceData is the data returned by the sdk you are using for Google/Facebook authentication.

Example: DDP.call('login', [{ google: serviceData }])

Usage with Full Meteor Client

If you have access to a full Meteor client implementation, possibly through something like meteor-client-bundler, then you’ll want your client-side call to look something like this:

  1. Accounts.callLoginMethod({
  2. methodArguments: [{ google: user }],
  3. userCallback: error => {
  4. if (error) {
  5. console.debug(error)
  6. }
  7. }
  8. })

See here for more information about this undocumented Meteor feature. The advantage is that this will set up your client-side authentication properly, so that (for example) Meteor.user() returns the current user correctly. Which is important if you are relying on that reactive data source to trigger other changes.