1.0.14 • Published 8 years ago

asteroid-oauth-mixin v1.0.14

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

Build Status Coverage Status

asteroid-oauth-mixin

An OAuth mixin for Asteroid.

Install

In node

Download the package:

npm install asteroid-oauth-mixin

Example usage

import {createClass} from "asteroid";
import * as asteroidOauthMixin from "asteroid-oauth-mixin";

const Asteroid = createClass([asteroidOauthMixin]);

const asteroid = new Asteroid({platform, endpoint});

/*
*   You need to define a `getServiceConfig` method (either in a mixin or on the
*   instance itself) which returns a plain object containing the configuration
*   for the specified provider. Such configurations are stored in the
*   `meteor_accounts_loginServiceConfiguration` collection, which the oauth
*   mixin automatically retrieves by subscribing to
*   `meteor.loginServiceConfiguration`, a subscription published - by default -
*   by the meteor server.
*   A naive implementation could be the following:
*/
asteroid.ddp.on("added", ({collection, id, fields}) => {
    if (collection === "meteor_accounts_loginServiceConfiguration") {
        asteroid.loginServiceConfiguration = {
            ...asteroid.loginServiceConfiguration,
            [id]: {
                _id: id,
                ...fields
            }
        };
    }
});
asteroid.getServiceConfig = function (providerName) {
    return this.loginServiceConfiguration[providerName];
}

/*
*   Somewhere in your code
*/

asteroid.loginWith("google")
    .then(() => console.log("login successful"))
    .catch(() => console.log("error logging in"))

If you use asteroid-collections-mixin:

import {createClass} from "asteroid";
import * as asteroidOauthMixin from "asteroid-oauth-mixin";
import * as asteroidCollectionsMixin from "asteroid-collections-mixin";

const Asteroid = createClass([asteroidCollectionsMixin, asteroidOauthMixin]);

const asteroid = new Asteroid({platform, endpoint});

/*
*   Somewhere in your code
*/

asteroid.loginWith("google")
    .then(() => console.log("login successful"))
    .catch(() => console.log("error logging in"))
1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago