Skip to content

gchallen/meteor-accounts-google-oauth

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%