Coder Social home page Coder Social logo

meteor-accounts-google-oauth's Introduction

accounts-google-oauth

A login handler for clients wishing to use a platform's native google sdk for sign on. Removes the requirement of the browser. Use in combination with accounts-google 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:

/*
  Settings would look like this
  {
    "google": {
      "client_secret": "MY_WEB_APP_SECRET",
      "client_id": "MY_WEB_APP_CLIENT_ID",
      "validClientIds": [
        "MY_WEB_APP_CLIENT_ID",
        "MY_IOS_APP_CLIENT_ID"
      ]
    }
  }
*/
const settings = Meteor.settings.google;

if (settings) {
  ServiceConfiguration.configurations.remove({
    service: 'google'
  });

  ServiceConfiguration.configurations.insert({
    service: 'google',
    clientId: settings.client_id,
    secret: settings.client_secret,
    validClientIds: Meteor.settings.google.validClientIds
  });
}

Usage from Client

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

  { google: serviceData }

Where serviceData is the data returned by the sdk you are using for Google 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:

Accounts.callLoginMethod({
  methodArguments: [{ google: user }], 
  userCallback: error => {
    if (error) {
      console.debug(error)
    }   
  }   
})

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.

meteor-accounts-google-oauth's People

Contributors

gchallen avatar hasantayyar avatar spencercarli avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

meteor-accounts-google-oauth's Issues

onCreateUser not called when inserting a new user

Hi,

My app has a firstName and lastName field in the user's profile. These are set in my app by Accounts.onCreateUser((options, user) => {...}.

This works with the regular accounts-google package, but not with this package, since this package tries to insert a user directly and onCreateUser isn't called.

My onCreateUser actually does a bunch more things and it's a bit problematic that it isn't called when using this package. I can come up with a hacky solution by removing this package and copying and pasting the code into my app and changing it to my needs, but it would be nice if we could come up with a real solution that works the same way as the other Meteor accounts-x packages.

The same problem exists with the RN Facebook snippet you posted on Medium.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.