From eb2e346332584ce29119e9862d07684a5724df7a Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Wed, 13 Dec 2017 15:42:46 +0100 Subject: [PATCH] Adding JWT auth. --- CHANGELOG.md | 4 +++- dependencies.list | 2 +- lib/user-methods.js | 21 +++++++++++++++++++-- tests/js/user-tests.js | 12 ++++++++++++ 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1107f19c..b5c6503d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,12 +6,14 @@ X.Y.Z Release notes ### Enhancements * Added property `Realm.isClosed` which indicates if a Realm instance is closed or not. +* [Object Server] Added JWT authenfication (#1548). ### Bug fixes * None. ### Internal -* None. +* [Object Server] Updated to Realm Object Server v2.2.0 for testing. + 2.0.13 Release notes (2017-12-8) ============================================================= diff --git a/dependencies.list b/dependencies.list index 3e987eb2..7dd93fcd 100644 --- a/dependencies.list +++ b/dependencies.list @@ -2,4 +2,4 @@ PACKAGE_NAME=realm-js VERSION=2.0.13 REALM_CORE_VERSION=4.0.2 REALM_SYNC_VERSION=2.1.8 -REALM_OBJECT_SERVER_VERSION=2.0.21 +REALM_OBJECT_SERVER_VERSION=2.2.0 diff --git a/lib/user-methods.js b/lib/user-methods.js index b0f4210c..f605e6e3 100644 --- a/lib/user-methods.js +++ b/lib/user-methods.js @@ -269,8 +269,25 @@ const staticMethods = { return _authenticate(this, server, json, callback); }, - _refreshAccessToken: refreshAccessToken - }; + authenticate(server, provider, options) { + checkTypes(arguments, ['string', 'string', 'object']) + + switch (provider) { + case 'jwt': + case 'JWT': + options.provider = 'jwt' + break + default: + return Promise.reject(`${provider} is not supported.`) + } + + return _authenticate(this, server, options) + }, + + + _refreshAccessToken: refreshAccessToken, +}; + const instanceMethods = { openManagementRealm() { diff --git a/tests/js/user-tests.js b/tests/js/user-tests.js index 404ba1fa..e3f11fd8 100644 --- a/tests/js/user-tests.js +++ b/tests/js/user-tests.js @@ -174,6 +174,18 @@ module.exports = { }); }, + testAuthenticateInvalidProvider() { + return Realm.Sync.User.authenticate('http://localhost:9080', 'FooBar', {}) + .then((user) => { Promise.reject() } ) + .catch((e) => { Promise.resolve() } ) + }, + + testAuthenticateJWT() { + return Realm.Sync.User.authenticate('http://localhost:9080', 'jwt', { token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ' }) + .then((user) => { Promise.resolve() } ) + .catch((e) => { Promise.reject(e) } ) + }, + testAll() { const all = Realm.Sync.User.all; TestCase.assertArrayLength(Object.keys(all), 0);