diff --git a/packages/accounts-meteor/.gitignore b/packages/accounts-meteorid/.gitignore similarity index 100% rename from packages/accounts-meteor/.gitignore rename to packages/accounts-meteorid/.gitignore diff --git a/packages/accounts-meteor/accounts-meteor.js b/packages/accounts-meteorid/accounts-meteorid.js similarity index 65% rename from packages/accounts-meteor/accounts-meteor.js rename to packages/accounts-meteorid/accounts-meteorid.js index 6d7fa011bb..06d261ef07 100644 --- a/packages/accounts-meteor/accounts-meteor.js +++ b/packages/accounts-meteorid/accounts-meteorid.js @@ -1,8 +1,8 @@ -Accounts.oauth.registerService("meteor"); +Accounts.oauth.registerService("meteorid"); if (Meteor.isClient) { // Options are documented in the meteor-auth package. - Meteor.loginWithMeteor = function (options, callback) { + Meteor.loginWithMeteorId = function (options, callback) { // support a callback without options if (! callback && typeof options === "function") { callback = options; @@ -10,6 +10,6 @@ if (Meteor.isClient) { } var credentialRequestCompleteCallback = Accounts.oauth.credentialRequestCompleteHandler(callback); - MeteorAccounts.requestCredential(options, credentialRequestCompleteCallback); + MeteorId.requestCredential(options, credentialRequestCompleteCallback); }; } diff --git a/packages/accounts-meteorid/meteorid.js b/packages/accounts-meteorid/meteorid.js new file mode 100644 index 0000000000..a9aab30894 --- /dev/null +++ b/packages/accounts-meteorid/meteorid.js @@ -0,0 +1,26 @@ +Accounts.oauth.registerService("meteorid"); + +if (Meteor.isClient) { + Meteor.loginWithMeteorId = function (options, callback) { + // support a callback without options + if (! callback && typeof options === "function") { + callback = options; + options = null; + } + + var credentialRequestCompleteCallback = + Accounts.oauth.credentialRequestCompleteHandler(callback); + MeteorId.requestCredential(options, credentialRequestCompleteCallback); + }; +} else { + Accounts.addAutopublishFields({ + // publish all fields including access token, which can legitimately be used + // from the client (if transmitted over ssl or on localhost). + forLoggedInUser: ['services.meteorid'], + forOtherUsers: [ + 'services.meteorid.username', + 'services.meteorid.profile', + 'services.meteorid.id' + ] + }); +} diff --git a/packages/accounts-meteor/package.js b/packages/accounts-meteorid/package.js similarity index 81% rename from packages/accounts-meteor/package.js rename to packages/accounts-meteorid/package.js index 1698095e40..f0b1c80fd2 100644 --- a/packages/accounts-meteor/package.js +++ b/packages/accounts-meteorid/package.js @@ -9,7 +9,7 @@ Package.on_use(function (api) { // Export Accounts (etc) to packages using this one. api.imply('accounts-base', ['client', 'server']); api.use('accounts-oauth', ['client', 'server']); - api.use('meteor-auth', ['client', 'server']); + api.use('meteorid', ['client', 'server']); - api.add_files("accounts-meteor.js"); + api.add_files("accounts-meteorid.js"); }); diff --git a/packages/meteor-auth/meteor_auth_client.js b/packages/meteor-auth/meteor_auth_client.js deleted file mode 100644 index d2f868708a..0000000000 --- a/packages/meteor-auth/meteor_auth_client.js +++ /dev/null @@ -1,64 +0,0 @@ -MeteorAccounts = {}; - -// Request Meteor Accounts credentials for the user -// @param options {optional} -// @param credentialRequestCompleteCallback {Function} Callback function to call on -// completion. Takes one argument, credentialToken on success, or Error on -// error. -// Options: -// - _redirectToLogin (boolean): uses a redirect to take the user to Meteor -// Accounts instead of a popup -// - _redirectUrl (string): a url to redirect to for handling the authorization -// code, instead of the default which goes to the registered service handler -// - _state (object): extra state to append to the authorization code -// request. The state will be stringified and prepended to other state with a -// comma. (i.e., the actual state parameter used will be ,). -// XXX It's very possible that there are only a few permutations of these -// options that make sense. For instance, our oauth server code only really -// handles the popup flow, so setting _redirectToLogin but not setting -// _redirectUrl won't work. Also, passing a credentialRequestCompleteCallback -// and also setting options._redirectToLogin doesn't make sense because the -// callback will never get called. -MeteorAccounts.requestCredential = function (options, credentialRequestCompleteCallback) { - // support both (options, callback) and (callback). - if (!credentialRequestCompleteCallback && typeof options === 'function') { - credentialRequestCompleteCallback = options; - options = {}; - } else if (!options) { - options = {}; - } - - var config = ServiceConfiguration.configurations.findOne({service: 'meteor'}); - if (!config) { - credentialRequestCompleteCallback && - credentialRequestCompleteCallback( - new ServiceConfiguration.ConfigError("Service not configured") - ); - return; - } - - var credentialToken = Random.id(); - var state = (options._state ? - JSON.stringify(state) + "," + credentialToken : - credentialToken); - - var loginUrl = - "https://accounts.meteor.com/authorize?" + - "state=" + state + - "&response_type=code&" + - "client_id=" + config.clientId + - "&redirect_uri=" + - (options._redirectUrl || Meteor.absoluteUrl("_oauth/meteor/close", { - secure: true - })); - if (options._redirectToLogin) { - window.location.assign(loginUrl); - } else { - Oauth.showPopup( - loginUrl, - _.bind(credentialRequestCompleteCallback, null, credentialToken), - { height: 406 } - ); - } -}; diff --git a/packages/meteor-auth/.gitignore b/packages/meteorid/.gitignore similarity index 100% rename from packages/meteor-auth/.gitignore rename to packages/meteorid/.gitignore diff --git a/packages/meteorid/meteorid_client.js b/packages/meteorid/meteorid_client.js new file mode 100644 index 0000000000..bb021e0dc9 --- /dev/null +++ b/packages/meteorid/meteorid_client.js @@ -0,0 +1,31 @@ +MeteorId = {}; + +// Request MeteorId credentials for the user +// @param credentialRequestCompleteCallback {Function} Callback function to call on +// completion. Takes one argument, credentialToken on success, or Error on +// error. +MeteorId.requestCredential = function (credentialRequestCompleteCallback) { + var config = ServiceConfiguration.configurations.findOne({service: 'meteorid'}); + if (!config) { + credentialRequestCompleteCallback && + credentialRequestCompleteCallback( + new ServiceConfiguration.ConfigError("Service not configured") + ); + return; + } + + var credentialToken = Random.id(); + + var loginUrl = + METEORID_URL + "/authorize?" + + "state=" + credentialToken + + "&response_type=code&" + + "client_id=" + config.clientId + + "&redirect_uri=" + Meteor.absoluteUrl("_oauth/meteor/close"); + + Oauth.showPopup( + loginUrl, + _.bind(credentialRequestCompleteCallback, null, credentialToken), + { height: 406 } + ); +}; diff --git a/packages/meteorid/meteorid_common.js b/packages/meteorid/meteorid_common.js new file mode 100644 index 0000000000..21a65afeed --- /dev/null +++ b/packages/meteorid/meteorid_common.js @@ -0,0 +1,2 @@ +// XXX fill me in! +METEORID_URL = ""; diff --git a/packages/meteor-auth/meteor_auth_configure.html b/packages/meteorid/meteorid_configure.html similarity index 76% rename from packages/meteor-auth/meteor_auth_configure.html rename to packages/meteorid/meteorid_configure.html index 173191101a..c7a41b3db5 100644 --- a/packages/meteor-auth/meteor_auth_configure.html +++ b/packages/meteorid/meteorid_configure.html @@ -1,6 +1,6 @@