Skip to content

Commit

Permalink
initial commit, code taken from: https://github.com/orionsoft/meteor-…
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorDiaconu committed Mar 28, 2018
0 parents commit e36d1ef
Show file tree
Hide file tree
Showing 28 changed files with 838 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
62 changes: 62 additions & 0 deletions .versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
accounts-base@1.2.17
accounts-oauth@1.1.15
allow-deny@1.0.5
babel-compiler@6.18.2
babel-runtime@1.0.1
base64@1.0.10
binary-heap@1.0.10
blaze@2.3.2
blaze-tools@1.0.10
boilerplate-generator@1.0.11
callback-hook@1.0.10
check@1.2.5
ddp@1.2.5
ddp-client@1.3.4
ddp-common@1.2.8
ddp-rate-limiter@1.0.7
ddp-server@1.3.14
deps@1.0.12
diff-sequence@1.0.7
ecmascript@0.7.3
ecmascript-runtime@0.3.15
ejson@1.0.13
geojson-utils@1.0.10
html-tools@1.0.11
htmljs@1.0.11
http@1.2.12
id-map@1.0.9
jquery@1.11.10
local-test:nicolaslopezj:apollo-accounts@3.2.2
localstorage@1.0.12
logging@1.1.17
meteor@1.6.1
minimongo@1.0.23
modules@0.8.2
modules-runtime@0.7.10
mongo@1.1.17
mongo-id@1.0.6
nicolaslopezj:apollo-accounts@3.2.2
npm-bcrypt@0.9.2
npm-mongo@2.2.24
oauth@1.1.13
oauth2@1.1.11
observe-sequence@1.0.16
ordered-dict@1.0.9
promise@0.8.8
random@1.0.10
rate-limit@1.0.8
reactive-var@1.0.11
reload@1.1.11
retry@1.0.9
routepolicy@1.0.12
service-configuration@1.0.11
spacebars@1.0.13
spacebars-compiler@1.1.0
tinytest@1.0.12
tmeasday:check-npm-versions@0.3.1
tracker@1.1.3
ui@1.0.12
underscore@1.0.10
url@1.1.0
webapp@1.3.15
webapp-hashing@1.0.9
80 changes: 80 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Changelog

### v3.2.3

* Changed graphql-loader to graphql-load to have more control

### v3.1.0

* Use http instead of meteor to make Facebook login.

### v3.0.1

* Fix bug with `tmeasday:check-npm-versions`.

### v3.0.0

* Use [orionsoft:graphql-loader](https://github.com/orionsoft/graphql-loader) to initialize package.
* Add user field to LoginMethodResponse [#23](https://github.com/nicolaslopezj/meteor-apollo-accounts/issues/23).

### v2.2.0

* Use async in all mutations.

### v2.1.0

* Add plainPassword option to createUser.

### v2.0.0

* Make `SchemaMutations`, `SchemaTypes` and `Resolvers` functions that receive options.

To migrate change:

* `SchemaMutations` to `SchemaMutations()`
* `SchemaTypes` to `SchemaTypes()`
* `Resolvers` to `Resolvers()`

### v1.4.0

* Login with linkedin.

### v1.3.7

* Fix destroyToken in logout.

### v1.3.6

* Fix error throwing on `loginWithPassword`.

### v1.3.5

* Fix production `standard-minifier-js` error.

### v1.3.4

* Add some oauth dependencies to only require installation of accounts-xx.
* Fix oauth login not throwing errors.

### v1.3.3

* Add `accounts-password` to weak dependencies.

### v1.3.2

* Fix `Mutation.createUser defined in resolvers, but not in schema`

### v1.3.1

* Don't use graphql-compiler
* Add conditional to password service mutations.

### v1.3.0

* Pass login method in error message when user tries to log in with the incorrect service.

### v1.2.0

* Conditional mutation if service is installed
* Accounts facebook
* Accounts google
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Meteor Apollo Accounts
39 changes: 39 additions & 0 deletions package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* global Package */

Package.describe({
name: 'cultofcoders:apollo-accounts',
version: '3.2.3',
// Brief, one-line summary of the package.
summary: 'Meteor accounts in GraphQL',
// URL to the Git repository containing the source code for this package.
git: 'https://github.com/cultofcoders/meteor-apollo-accounts',
// By default, Meteor will default to using README.md for documentation.
// To avoid submitting documentation, set this field to null.
documentation: 'README.md',
});

Package.onUse(function(api) {
api.versionsFrom('1.4.1.2');

api.use(
[
'tmeasday:check-npm-versions@0.3.1',
'check',
'accounts-base',
'oauth2',
'npm-bcrypt',
'random',
'ecmascript',
'http',
'random',
'oauth',
'service-configuration',
'accounts-oauth',
],
'server'
);

api.mainModule('src/index.js', 'server');
});

Package.onTest(function(api) {});
32 changes: 32 additions & 0 deletions src/Auth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export default function (options) {
return `
# Type returned when the user logs in
type LoginMethodResponse {
# Id of the user logged in user
id: String!
# Token of the connection
token: String!
# Expiration date for the token
tokenExpires: Float!
# The logged in user
user: User
}
input CreateUserProfileInput {
${options.CreateUserProfileInput}
}
type SuccessResponse {
# True if it succeeded
success: Boolean
}
# A hashsed password
input HashedPassword {
# The hashed password
digest: String!
# Algorithm used to hash the password
algorithm: String!
}
`
}
11 changes: 11 additions & 0 deletions src/LoginMethodResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {Meteor} from 'meteor/meteor'

export default function (options) {
return {
LoginMethodResponse: {
user ({id}) {
return Meteor.users.findOne(id)
}
}
}
}
5 changes: 5 additions & 0 deletions src/Mutation/changePassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import callMethod from '../callMethod'

export default async function (root, {oldPassword, newPassword}, context) {
return callMethod(context, 'changePassword', oldPassword, newPassword)
}
15 changes: 15 additions & 0 deletions src/Mutation/createUser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import callMethod from '../callMethod'
import hashPassword from './hashPassword'
import {Meteor} from 'meteor/meteor'

export default async function (root, options, context) {
Meteor._nodeCodeMustBeInFiber()
if (!options.password && !options.plainPassword) {
throw new Error('Password is required')
}
if (!options.password) {
options.password = hashPassword(options.plainPassword)
delete options.plainPassword
}
return callMethod(context, 'createUser', options)
}
8 changes: 8 additions & 0 deletions src/Mutation/forgotPassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import callMethod from '../callMethod'

export default async function (root, {email}, context) {
callMethod(context, 'forgotPassword', {email})
return {
success: true
}
}
131 changes: 131 additions & 0 deletions src/Mutation/hashPassword.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* eslint-disable */

export const SHA256 = function (s) {
var chrsz = 8;
var hexcase = 0;

function safe_add (x, y) {
var lsw = (x & 0xFFFF) + (y & 0xFFFF);
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xFFFF);
}

function S (X, n) { return ( X >>> n ) | (X << (32 - n)); }
function R (X, n) { return ( X >>> n ); }
function Ch(x, y, z) { return ((x & y) ^ ((~x) & z)); }
function Maj(x, y, z) { return ((x & y) ^ (x & z) ^ (y & z)); }
function Sigma0256(x) { return (S(x, 2) ^ S(x, 13) ^ S(x, 22)); }
function Sigma1256(x) { return (S(x, 6) ^ S(x, 11) ^ S(x, 25)); }
function Gamma0256(x) { return (S(x, 7) ^ S(x, 18) ^ R(x, 3)); }
function Gamma1256(x) { return (S(x, 17) ^ S(x, 19) ^ R(x, 10)); }

function core_sha256 (m, l) {
var K = [0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5, 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5, 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3, 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174, 0xE49B69C1, 0xEFBE4786, 0xFC19DC6, 0x240CA1CC, 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA, 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7, 0xC6E00BF3, 0xD5A79147, 0x6CA6351, 0x14292967, 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13, 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85, 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3, 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070, 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5, 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3, 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208, 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2];
var HASH = [0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19];
var W = new Array(64);
var a, b, c, d, e, f, g, h;
var T1, T2;

m[l >> 5] |= 0x80 << (24 - l % 32);
m[((l + 64 >> 9) << 4) + 15] = l;

for ( let i = 0; i<m.length; i+=16 ) {
a = HASH[0];
b = HASH[1];
c = HASH[2];
d = HASH[3];
e = HASH[4];
f = HASH[5];
g = HASH[6];
h = HASH[7];

for ( let j = 0; j<64; j++) {
if (j < 16) W[j] = m[j + i];
else W[j] = safe_add(safe_add(safe_add(Gamma1256(W[j - 2]), W[j - 7]), Gamma0256(W[j - 15])), W[j - 16]);

T1 = safe_add(safe_add(safe_add(safe_add(h, Sigma1256(e)), Ch(e, f, g)), K[j]), W[j]);
T2 = safe_add(Sigma0256(a), Maj(a, b, c));

h = g;
g = f;
f = e;
e = safe_add(d, T1);
d = c;
c = b;
b = a;
a = safe_add(T1, T2);
}

HASH[0] = safe_add(a, HASH[0]);
HASH[1] = safe_add(b, HASH[1]);
HASH[2] = safe_add(c, HASH[2]);
HASH[3] = safe_add(d, HASH[3]);
HASH[4] = safe_add(e, HASH[4]);
HASH[5] = safe_add(f, HASH[5]);
HASH[6] = safe_add(g, HASH[6]);
HASH[7] = safe_add(h, HASH[7]);
}
return HASH;
}

function str2binb (str) {
var bin = [];
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz) {
bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (24 - i%32);
}
return bin;
}

function Utf8Encode(string) {
// METEOR change:
// The webtoolkit.info version of this code added this
// Utf8Encode function (which does seem necessary for dealing
// with arbitrary Unicode), but the following line seems
// problematic:
//
// string = string.replace(/\r\n/g,"\n");
var utftext = "";

for (var n = 0; n < string.length; n++) {

var c = string.charCodeAt(n);

if (c < 128) {
utftext += String.fromCharCode(c);
}
else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
}
else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}

}

return utftext;
}

function binb2hex (binarray) {
var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
var str = "";
for(var i = 0; i < binarray.length * 4; i++) {
str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
}
return str;
}

s = Utf8Encode(s);
return binb2hex(core_sha256(str2binb(s), s.length * chrsz));
}

export default function (password) {
return {
digest: SHA256(password),
algorithm: 'sha-256'
}
}
Loading

0 comments on commit e36d1ef

Please sign in to comment.