Skip to content

Commit fb57d91

Browse files
committed
Merge pull request #1110 from ParsePlatform/flovilmart.missingSessionInstallationId
Properly sets installationId on creating session with 3rd party auth
2 parents 414af99 + a31baa4 commit fb57d91

File tree

5 files changed

+51
-25
lines changed

5 files changed

+51
-25
lines changed

Diff for: spec/OAuth.spec.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,11 @@ describe('OAuth', function() {
204204
myoauth: getMockMyOauthProvider().authData
205205
}
206206
};
207-
var headers = {'X-Parse-Application-Id': 'test',
208-
'X-Parse-REST-API-Key': 'rest',
209-
'Content-Type': 'application/json' }
210207

211208
var options = {
212209
headers: {'X-Parse-Application-Id': 'test',
213210
'X-Parse-REST-API-Key': 'rest',
211+
'X-Parse-Installation-Id': 'yolo',
214212
'Content-Type': 'application/json' },
215213
url: 'http://localhost:8378/1/users',
216214
body: JSON.stringify(jsonBody)
@@ -224,9 +222,19 @@ describe('OAuth', function() {
224222
createOAuthUser((error, response, body) => {
225223
expect(error).toBe(null);
226224
var b = JSON.parse(body);
225+
ok(b.sessionToken);
227226
expect(b.objectId).not.toBeNull();
228227
expect(b.objectId).not.toBeUndefined();
229-
done();
228+
var sessionToken = b.sessionToken;
229+
var q = new Parse.Query("_Session");
230+
q.equalTo('sessionToken', sessionToken);
231+
q.first({useMasterKey: true}).then((res) => {
232+
expect(res.get("installationId")).toEqual('yolo');
233+
done();
234+
}).fail((err) => {
235+
fail('should not fail fetching the session');
236+
done();
237+
})
230238
});
231239

232240
});

Diff for: spec/ParseUser.spec.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -1768,9 +1768,37 @@ describe('Parse.User testing', () => {
17681768
});
17691769
});
17701770

1771-
it('user get session from token', (done) => {
1771+
it('user get session from token on signup', (done) => {
17721772
Parse.Promise.as().then(() => {
17731773
return Parse.User.signUp("finn", "human", { foo: "bar" });
1774+
}).then((user) => {
1775+
request.get({
1776+
headers: {
1777+
'X-Parse-Application-Id': 'test',
1778+
'X-Parse-Session-Token': user.getSessionToken(),
1779+
'X-Parse-REST-API-Key': 'rest'
1780+
},
1781+
url: 'http://localhost:8378/1/sessions/me',
1782+
}, (error, response, body) => {
1783+
expect(error).toBe(null);
1784+
var b = JSON.parse(body);
1785+
expect(typeof b.sessionToken).toEqual('string');
1786+
expect(typeof b.createdWith).toEqual('object');
1787+
expect(b.createdWith.action).toEqual('signup');
1788+
expect(typeof b.user).toEqual('object');
1789+
expect(b.user.objectId).toEqual(user.id);
1790+
done();
1791+
});
1792+
});
1793+
});
1794+
1795+
it('user get session from token on login', (done) => {
1796+
Parse.Promise.as().then(() => {
1797+
return Parse.User.signUp("finn", "human", { foo: "bar" });
1798+
}).then((user) => {
1799+
return Parse.User.logOut().then(() => {
1800+
return Parse.User.logIn("finn", "human");
1801+
})
17741802
}).then((user) => {
17751803
request.get({
17761804
headers: {

Diff for: src/RestWrite.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,11 +327,11 @@ RestWrite.prototype.transformUser = function() {
327327
objectId: this.objectId()
328328
},
329329
createdWith: {
330-
'action': 'login',
330+
'action': 'signup',
331331
'authProvider': this.storage['authProvider'] || 'password'
332332
},
333333
restricted: false,
334-
installationId: this.data.installationId,
334+
installationId: this.auth.installationId,
335335
expiresAt: Parse._encode(expiresAt)
336336
};
337337
if (this.response && this.response.response) {

Diff for: src/Routers/UsersRouter.js

+6-16
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,7 @@ export class UsersRouter extends ClassesRouter {
2727
req.body = data;
2828
req.params.className = '_User';
2929

30-
//req.config.userController.setEmailVerifyToken(req.body);
31-
3230
return super.handleCreate(req);
33-
34-
// if (req.config.verifyUserEmails) {
35-
// // Send email as fire-and-forget once the user makes it into the DB.
36-
// p.then(() => {
37-
// req.config.userController.sendVerificationEmail(req.body);
38-
// });
39-
// }
40-
// return p;
4131
}
4232

4333
handleUpdate(req) {
@@ -102,9 +92,9 @@ export class UsersRouter extends ClassesRouter {
10292
let token = 'r:' + cryptoUtils.newToken();
10393
user.sessionToken = token;
10494
delete user.password;
105-
95+
10696
// Sometimes the authData still has null on that keys
107-
// https://github.com/ParsePlatform/parse-server/issues/935
97+
// https://github.com/ParsePlatform/parse-server/issues/935
10898
if (user.authData) {
10999
Object.keys(user.authData).forEach((provider) => {
110100
if (user.authData[provider] === null) {
@@ -115,7 +105,7 @@ export class UsersRouter extends ClassesRouter {
115105
delete user.authData;
116106
}
117107
}
118-
108+
119109
req.config.filesController.expandFilesInObject(req.config, user);
120110

121111
let expiresAt = new Date();
@@ -165,14 +155,14 @@ export class UsersRouter extends ClassesRouter {
165155
}
166156
return Promise.resolve(success);
167157
}
168-
158+
169159
handleResetRequest(req) {
170160
let { email } = req.body;
171161
if (!email) {
172162
throw new Parse.Error(Parse.Error.EMAIL_MISSING, "you must provide an email");
173163
}
174164
let userController = req.config.userController;
175-
165+
176166
return userController.sendPasswordResetEmail(email).then((token) => {
177167
return Promise.resolve({
178168
response: {}
@@ -181,7 +171,7 @@ export class UsersRouter extends ClassesRouter {
181171
throw new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, `no user found with email ${email}`);
182172
});
183173
}
184-
174+
185175

186176
mountRoutes() {
187177
this.route('GET', '/users', req => { return this.handleFind(req); });

Diff for: src/middlewares.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function handleParseHeaders(req, res, next) {
9797
// Client keys are not required in parse-server, but if any have been configured in the server, validate them
9898
// to preserve original behavior.
9999
let keys = ["clientKey", "javascriptKey", "dotNetKey", "restAPIKey"];
100-
100+
101101
// We do it with mismatching keys to support no-keys config
102102
var keyMismatch = keys.reduce(function(mismatch, key){
103103

@@ -107,7 +107,7 @@ function handleParseHeaders(req, res, next) {
107107
}
108108
return mismatch;
109109
}, 0);
110-
110+
111111
// All keys mismatch
112112
if (keyMismatch == keys.length) {
113113
return invalidRequest(req, res);

0 commit comments

Comments
 (0)