Adding password provider support to Realm.Sync.User.authenticate
This commit is contained in:
parent
26ed091c77
commit
58311c0087
|
@ -4,6 +4,7 @@ X.Y.Z Release notes
|
||||||
* None.
|
* None.
|
||||||
|
|
||||||
### Enhancements
|
### Enhancements
|
||||||
|
* [Object Server] Added method `Realm.Sync.User.authenticate` to unify authentication of users.
|
||||||
* [Object Server] Added JWT authenfication (#1548).
|
* [Object Server] Added JWT authenfication (#1548).
|
||||||
|
|
||||||
### Bug fixes
|
### Bug fixes
|
||||||
|
|
|
@ -272,19 +272,25 @@ const staticMethods = {
|
||||||
authenticate(server, provider, options) {
|
authenticate(server, provider, options) {
|
||||||
checkTypes(arguments, ['string', 'string', 'object'])
|
checkTypes(arguments, ['string', 'string', 'object'])
|
||||||
|
|
||||||
switch (provider) {
|
var json = {}
|
||||||
|
switch (provider.toLowerCase()) {
|
||||||
case 'jwt':
|
case 'jwt':
|
||||||
case 'JWT':
|
json.provider = 'jwt'
|
||||||
options.provider = 'jwt'
|
json.token = options.token;
|
||||||
|
break
|
||||||
|
case 'password':
|
||||||
|
json.provider = 'password'
|
||||||
|
json.user_info = { password: options.password }
|
||||||
|
json.data = options.username
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
return Promise.reject(`${provider} is not supported.`)
|
Object.assign(json, options)
|
||||||
|
json.provider = provider
|
||||||
}
|
}
|
||||||
|
|
||||||
return _authenticate(this, server, options)
|
return _authenticate(this, server, json)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
_refreshAccessToken: refreshAccessToken,
|
_refreshAccessToken: refreshAccessToken,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -136,6 +136,19 @@ module.exports = {
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
testAuthenticateWithPassword() {
|
||||||
|
const username = uuid();
|
||||||
|
return Realm.Sync.User.register('http://localhost:9080', username, 'password').then((user) => {
|
||||||
|
user.logout();
|
||||||
|
return Realm.Sync.User.authenticate('http://localhost:9080', 'password', { username: username, password: 'password' });
|
||||||
|
}).then((user => {
|
||||||
|
assertIsUser(user);
|
||||||
|
const realm = new Realm({ sync: { user: user, url: 'realm://localhost:9080/~/test' } });
|
||||||
|
TestCase.assertInstanceOf(realm, Realm);
|
||||||
|
realm.close();
|
||||||
|
}))
|
||||||
|
},
|
||||||
|
|
||||||
testLoginMissingUsername() {
|
testLoginMissingUsername() {
|
||||||
TestCase.assertThrows(() => Realm.Sync.User.login('http://localhost:9080', undefined, 'password'));
|
TestCase.assertThrows(() => Realm.Sync.User.login('http://localhost:9080', undefined, 'password'));
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue