Permalink
Browse files

initial

  • Loading branch information...
svasva committed Jan 12, 2013
0 parents commit 669cb1d786ea4cf6772b55dd435c78a27d868858
Showing with 127 additions and 0 deletions.
  1. +17 −0 package.js
  2. +9 −0 smart.json
  3. +27 −0 vk_client.js
  4. +4 −0 vk_common.js
  5. +14 −0 vk_configure.html
  6. +12 −0 vk_configure.js
  7. +44 −0 vk_server.js
@@ -0,0 +1,17 @@
+Package.describe({
+ summary: "Login service for VKontakte 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(['vk_configure.html', 'vk_configure.js'], 'client');
+
+ api.add_files('vk_common.js', ['client', 'server']);
+ api.add_files('vk_server.js', 'server');
+ api.add_files('vk_client.js', 'client');
+});
+
@@ -0,0 +1,9 @@
+{
+ "name": "accounts-vkontakte",
+ "description": "Login service for VKontakte accounts",
+ "homepage": "https://github.com/erundook/meteor-accounts-vkontakte",
+ "author": "Vitaly A. Sorokin",
+ "version": "0.1.0",
+ "git": "https://github.com/erundook/meteor-accounts-vkontakte.git"
+}
+
@@ -0,0 +1,27 @@
+(function () {
+ Meteor.loginWithVkontakte = function (options, callback) {
+ // support both (options, callback) and (callback).
+ if (!callback && typeof options === 'function') {
+ callback = options;
+ options = {};
+ }
+
+ var config = Accounts.loginServiceConfiguration.findOne({service: 'vkontakte'});
+ if (!config) {
+ callback && callback(new Accounts.ConfigError("Service not configured"));
+ return;
+ }
+
+ var state = Meteor.uuid();
+ var loginUrl =
+ 'https://oauth.vk.com/authorize' +
+ '?client_id=' + config.clientId +
+ '&scope=' + config.scope +
+ '&redirect_uri=' + Meteor.absoluteUrl('_oauth/vkontakte?close=close', {replaceLocalhost: true}) +
+ '&response_type=code';
+
+ Accounts.oauth.initiateLogin(state, loginUrl, callback);
+ };
+
+}) ();
+
@@ -0,0 +1,4 @@
+if (!Accounts.vkontakte) {
+ Accounts.vkontakte = {};
+}
+
@@ -0,0 +1,14 @@
+<template name="configureLoginServiceDialogForVkontakte">
+ <p>
+ First, you'll need to register your client on Vkontakte. Follow these steps:
+ </p>
+ <ol>
+ <li>
+ Visit <a href="http://vk.com/editapp?act=create" target="_blank">http://vk.com/editapp?act=create</a>
+ </li>
+ <li>
+ Set Callback URL to: <span class="url">{{siteUrl}}_oauth/vkontakte?close=close</span>
+ </li>
+ </ol>
+</template>
+
@@ -0,0 +1,12 @@
+Template.configureLoginServiceDialogForVkontakte.siteUrl = function () {
+ return Meteor.absoluteUrl({replaceLocalhost: true});
+};
+
+Template.configureLoginServiceDialogForVkontakte.fields = function () {
+ return [
+ {property: 'clientId', label: 'App Id'},
+ {property: 'secret', label: 'App Secret'},
+ {property: 'scope', label: "Scope"}
+ ];
+};
+
@@ -0,0 +1,44 @@
+(function () {
+
+ Accounts.oauth.registerService('vkontakte', 2, function(query) {
+
+ var accessToken = getAccessToken(query);
+
+ return {
+ serviceData: {
+ id: accessToken.user.id,
+ accessToken: accessToken.access_token,
+ username: accessToken.user.username
+ },
+ options: {
+ profile: {
+ name: accessToken.user.full_name,
+ picture: accessToken.user.profile_picture
+ }
+ }
+ };
+ });
+
+ var getAccessToken = function (query) {
+ var config = Accounts.loginServiceConfiguration.findOne({service: 'vkontakte'});
+ if (!config)
+ throw new Accounts.ConfigError("Service not configured");
+
+ var result = Meteor.http.post(
+ "https://oauth.vk.com/access_token", {params: {
+ client_id: config.clientId,
+ client_secret: config.secret,
+ code: query.code,
+ redirect_uri: Meteor.absoluteUrl("_oauth/vkontakte?close=close", {replaceLocalhost: true})
+ }});
+
+ if (result.error) // if the http response was an error
+ throw result.error;
+ if (typeof result.content === "string")
+ result.content = JSON.parse(result.content);
+ if (result.content.error) // if the http response was a json object with an error attribute
+ throw result.content;
+ return result.content;
+ };
+})();
+

0 comments on commit 669cb1d

Please sign in to comment.