accounts-meetup package

This commit is contained in:
Matt DeBergalis
2013-03-10 15:10:22 -07:00
parent 0bac1b3e2d
commit 71f54afccd
7 changed files with 128 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
(function () {
Meteor.loginWithMeetup = function (options, callback) {
// support both (options, callback) and (callback).
if (!callback && typeof options === 'function') {
callback = options;
options = {};
}
var config = Accounts.loginServiceConfiguration.findOne({service: 'meetup'});
if (!config) {
callback && callback(new Accounts.ConfigError("Service not configured"));
return;
}
var state = Random.id();
var loginUrl =
'https://secure.meetup.com/oauth2/authorize' +
'?client_id=' + config.clientId +
'&response_type=code' +
'&redirect_uri=' + Meteor.absoluteUrl('_oauth/meetup?close') +
'&state=' + state;
Accounts.oauth.initiateLogin(state, loginUrl, callback, {width: 900, height: 450});
};
}) ();

View File

@@ -0,0 +1,3 @@
if (!Accounts.meetup) {
Accounts.meetup = {};
}

View File

@@ -0,0 +1,20 @@
<template name="configureLoginServiceDialogForMeetup">
<p>
First, you'll need to get a Meetup Client ID. Follow these steps:
</p>
<ol>
<li>
Visit <a href="http://www.meetup.com/meetup_api/oauth_consumers/create/" target="blank">http://www.meetup.com/meetup_api/oauth_consumers/create/</a>
</li>
<li>
Set the Consumer name to the name of your application.
</li>
<li>
Optionally set the Application Website to the URL of your
website. You can leave this blank.
</li>
<li>
Set the <b>Redirect URI</b> to: <span class="url">{{siteUrl}}</span>. (Do not append a path to this URL.)
</li>
</ol>
</template>

View File

@@ -0,0 +1,10 @@
Template.configureLoginServiceDialogForMeetup.siteUrl = function () {
return Meteor.absoluteUrl();
};
Template.configureLoginServiceDialogForMeetup.fields = function () {
return [
{property: 'clientId', label: 'Key'},
{property: 'secret', label: 'Secret'}
];
};

View File

@@ -0,0 +1,5 @@
#login-buttons-image-meetup.login-image {
top: 8px;
height: 11px;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAALCAYAAAB24g05AAAEJGlDQ1BJQ0MgUHJvZmlsZQAAOBGFVd9v21QUPolvU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QmCC);
}

View File

@@ -0,0 +1,47 @@
(function () {
Accounts.oauth.registerService('meetup', 2, function(query) {
var accessToken = getAccessToken(query);
var identity = getIdentity(accessToken);
return {
serviceData: {
id: identity.id,
accessToken: accessToken
},
options: {profile: {name: identity.name}}
};
});
var getAccessToken = function (query) {
var config = Accounts.loginServiceConfiguration.findOne({service: 'meetup'});
if (!config)
throw new Accounts.ConfigError("Service not configured");
var result = Meteor.http.post(
"https://secure.meetup.com/oauth2/access", {headers: {Accept: 'application/json'}, params: {
code: query.code,
client_id: config.clientId,
client_secret: config.secret,
grant_type: 'authorization_code',
redirect_uri: Meteor.absoluteUrl("_oauth/meetup?close"),
state: query.state
}});
if (result.error) // if the http response was an error
throw result.error;
if (result.data.error) // if the http response was a json object with an error attribute
throw result.data;
return result.data.access_token;
};
var getIdentity = function (accessToken) {
var result = Meteor.http.get(
"https://secure.meetup.com/2/members",
{params: {member_id: 'self', access_token: accessToken}});
if (result.error)
throw result.error;
return result.data.results && result.data.results[0];
};
}) ();

View File

@@ -0,0 +1,18 @@
Package.describe({
summary: "Login service for Meetup accounts"
});
Package.on_use(function(api) {
api.use('accounts-base', ['client', 'server']);
api.use('accounts-oauth2-helper', ['client', 'server']);
api.use('http', ['client', 'server']);
api.use('templating', 'client');
api.add_files(
['meetup_login_button.css', 'meetup_configure.html', 'meetup_configure.js'],
'client');
api.add_files('meetup_common.js', ['client', 'server']);
api.add_files('meetup_server.js', 'server');
api.add_files('meetup_client.js', 'client');
});