1.0.14 • Published 10 years ago

asteroid-oauth-mixin v1.0.14

Weekly downloads
3
License
MIT
Repository
github
Last release
10 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

10 years ago

1.0.13

10 years ago

1.0.12

10 years ago

1.0.11

10 years ago

1.0.10

10 years ago

1.0.9

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago