Skip to content

Commit e941acc

Browse files
committed
adds ability to pass custom installationId to create sessions in cloud code
1 parent 2b0c39c commit e941acc

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

spec/ParseServerRESTController.spec.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ describe('ParseServerRESTController', () => {
104104
});
105105

106106
it('ensures no session token is created on creating users', (done) => {
107-
RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}).then(() => {
107+
RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}).then((user) => {
108+
expect(user.sessionToken).toBeUndefined();
108109
let query = new Parse.Query('_Session');
109110
return query.find({useMasterKey: true});
110111
}).then(sessions => {
@@ -115,4 +116,19 @@ describe('ParseServerRESTController', () => {
115116
done();
116117
});
117118
});
119+
120+
it('ensures a session token is created when passing installationId != cloud', (done) => {
121+
RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}, {installationId: 'my-installation'}).then((user) => {
122+
expect(user.sessionToken).not.toBeUndefined();
123+
let query = new Parse.Query('_Session');
124+
return query.find({useMasterKey: true});
125+
}).then(sessions => {
126+
expect(sessions.length).toBe(1);
127+
expect(sessions[0].get('installationId')).toBe('my-installation');
128+
done();
129+
}, (err) => {
130+
jfail(err);
131+
done();
132+
});
133+
});
118134
});

src/ParseServerRESTController.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ function getSessionToken(options) {
1111
return Parse.Promise.as(null);
1212
}
1313

14-
function getAuth(options, config) {
14+
function getAuth(options = {}, config) {
15+
const installationId = options.installationId || 'cloud';
1516
if (options.useMasterKey) {
16-
return Parse.Promise.as(new Auth.Auth({config, isMaster: true, installationId: 'cloud' }));
17+
return Parse.Promise.as(new Auth.Auth({config, isMaster: true, installationId }));
1718
}
1819
return getSessionToken(options).then((sessionToken) => {
1920
if (sessionToken) {
2021
options.sessionToken = sessionToken;
2122
return Auth.getAuthForSessionToken({
2223
config,
2324
sessionToken: sessionToken,
24-
installationId: 'cloud'
25+
installationId
2526
});
2627
} else {
27-
return Parse.Promise.as(new Auth.Auth({ config, installationId: 'cloud' }));
28+
return Parse.Promise.as(new Auth.Auth({ config, installationId }));
2829
}
2930
})
3031
}

0 commit comments

Comments
 (0)