mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Rename meteorid packages
This commit is contained in:
@@ -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);
|
||||
};
|
||||
}
|
||||
26
packages/accounts-meteorid/meteorid.js
Normal file
26
packages/accounts-meteorid/meteorid.js
Normal file
@@ -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'
|
||||
]
|
||||
});
|
||||
}
|
||||
@@ -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");
|
||||
});
|
||||
@@ -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 <stringified state
|
||||
// from objects>,<other state>).
|
||||
// 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 }
|
||||
);
|
||||
}
|
||||
};
|
||||
31
packages/meteorid/meteorid_client.js
Normal file
31
packages/meteorid/meteorid_client.js
Normal file
@@ -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 }
|
||||
);
|
||||
};
|
||||
2
packages/meteorid/meteorid_common.js
Normal file
2
packages/meteorid/meteorid_common.js
Normal file
@@ -0,0 +1,2 @@
|
||||
// XXX fill me in!
|
||||
METEORID_URL = "";
|
||||
@@ -1,6 +1,6 @@
|
||||
<template name="configureLoginServiceDialogForMeteor">
|
||||
<p>
|
||||
First, you'll need to get a Meteor Accounts Client ID.
|
||||
First, you'll need to get a MeteorId Client ID.
|
||||
Set Authorized Redirect URIs to:
|
||||
<span class="url">
|
||||
{{siteUrl}}_oauth/meteor?close
|
||||
@@ -1,6 +1,6 @@
|
||||
MeteorAccounts = {};
|
||||
MeteorId = {};
|
||||
|
||||
Oauth.registerService("meteor", 2, null, function (query) {
|
||||
Oauth.registerService("meteorid", 2, null, function (query) {
|
||||
var response = getTokens(query);
|
||||
var accessToken = response.accessToken;
|
||||
var identity = getIdentity(accessToken);
|
||||
@@ -37,7 +37,7 @@ var getTokens = function (query) {
|
||||
var response;
|
||||
try {
|
||||
response = HTTP.post(
|
||||
"https://accounts.meteor.com/token", {
|
||||
METEORID_URL + "/token", {
|
||||
params: {
|
||||
grant_type: "authorization_code",
|
||||
code: query.code,
|
||||
@@ -50,14 +50,14 @@ var getTokens = function (query) {
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
throw _.extend(new Error("Failed to complete OAuth handshake with Meteor Accounts. "
|
||||
throw _.extend(new Error("Failed to complete OAuth handshake with MeteorId. "
|
||||
+ err.message),
|
||||
{response: err.response});
|
||||
}
|
||||
|
||||
if (! response.data || response.data.error) {
|
||||
// if the http response was a json object with an error attribute
|
||||
throw new Error("Failed to complete OAuth handshake with Meteor Accounts. " +
|
||||
throw new Error("Failed to complete OAuth handshake with MeteorId. " +
|
||||
response.data.error);
|
||||
} else {
|
||||
return {
|
||||
@@ -71,14 +71,14 @@ var getTokens = function (query) {
|
||||
var getIdentity = function (accessToken) {
|
||||
try {
|
||||
return HTTP.get(
|
||||
"https://accounts.meteor.com/identity",
|
||||
METEORID_URL + "/identity",
|
||||
{params: {access_token: accessToken}}).data;
|
||||
} catch (err) {
|
||||
throw _.extend(new Error("Failed to fetch identity from Meteor Accounts. " + err.message),
|
||||
throw _.extend(new Error("Failed to fetch identity from MeteorId. " + err.message),
|
||||
{response: err.response});
|
||||
}
|
||||
};
|
||||
|
||||
MeteorAccounts.retrieveCredential = function(credentialToken) {
|
||||
MeteorId.retrieveCredential = function(credentialToken) {
|
||||
return Oauth.retrieveCredential(credentialToken);
|
||||
};
|
||||
@@ -10,10 +10,11 @@ Package.on_use(function (api) {
|
||||
api.use(['underscore', 'service-configuration'], ['client', 'server']);
|
||||
api.use(['random', 'templating'], 'client');
|
||||
|
||||
api.export('MeteorAccounts');
|
||||
api.export('MeteorId');
|
||||
|
||||
api.add_files(['meteor_auth_configure.html',
|
||||
'meteor_auth_configure.js'], 'client');
|
||||
api.add_files('meteor_auth_server.js', 'server');
|
||||
api.add_files('meteor_auth_client.js', 'client');
|
||||
api.add_files('meteorid_common.js');
|
||||
api.add_files(['meteorid_configure.html',
|
||||
'meteorid_configure.js'], 'client');
|
||||
api.add_files('meteorid_server.js', 'server');
|
||||
api.add_files('meteorid_client.js', 'client');
|
||||
});
|
||||
Reference in New Issue
Block a user