From e48cd853b02ef06ab7cf6000290b6849d229b6ac Mon Sep 17 00:00:00 2001 From: tejasranade Date: Wed, 7 Mar 2018 13:29:44 -0500 Subject: [PATCH 1/2] Use long form clientID in MIC endpoints --- src/core/identity/mic.js | 26 ++++++-------------------- src/core/identity/mic.spec.js | 4 ++++ src/core/request/network.js | 26 ++++++++++++++++++++++++-- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/src/core/identity/mic.js b/src/core/identity/mic.js index c7ef2df1c..9fefee5c4 100644 --- a/src/core/identity/mic.js +++ b/src/core/identity/mic.js @@ -226,7 +226,7 @@ export class MobileIdentityConnect extends Identity { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - authType: AuthType.App, + authType: AuthType.Client, url: url.format({ protocol: this.client.micProtocol, host: this.client.micHost, @@ -238,7 +238,8 @@ export class MobileIdentityConnect extends Identity { client_id: clientId, redirect_uri: redirectUri, code: code - } + }, + clientId: clientId }); return request.execute().then(response => response.data); } @@ -249,7 +250,7 @@ export class MobileIdentityConnect extends Identity { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, - authType: AuthType.App, + authType: AuthType.Client, url: url.format({ protocol: this.client.micProtocol, host: this.client.micHost, @@ -261,6 +262,7 @@ export class MobileIdentityConnect extends Identity { redirect_uri: redirectUri, refresh_token: token }, + clientId: clientId, properties: options.properties, timeout: options.timeout }); @@ -268,23 +270,7 @@ export class MobileIdentityConnect extends Identity { } logout(user, options = {}) { - const request = new KinveyRequest({ - method: RequestMethod.GET, - headers: { - 'Content-Type': 'application/x-www-form-urlencoded' - }, - authType: AuthType.App, - url: url.format({ - protocol: this.client.micProtocol, - host: this.client.micHost, - pathname: '/oauth/invalidate', - query: { - user: user._id - } - }), - properties: options.properties - }); - return request.execute().then(response => response.data); + return Promise.resolve(); } /** diff --git a/src/core/identity/mic.spec.js b/src/core/identity/mic.spec.js index fe66ba23d..c7653e13d 100644 --- a/src/core/identity/mic.spec.js +++ b/src/core/identity/mic.spec.js @@ -325,6 +325,10 @@ describe('MobileIdentityConnect', () => { '/oauth/token', `grant_type=authorization_code&client_id=${encodeURIComponent(client.appKey+'.'+micId)}&redirect_uri=${encodeURIComponent(redirectUri)}&code=${code}` ) + .basicAuth({ + user: client.appKey + '.' + micId, + pass: client.appSecret + }) .reply(200, token, { 'Content-Type': 'application/json; charset=utf-8' }); diff --git a/src/core/request/network.js b/src/core/request/network.js index d6d22b903..62a870f6a 100644 --- a/src/core/request/network.js +++ b/src/core/request/network.js @@ -30,7 +30,8 @@ export const AuthType = { Default: 'Default', Master: 'Master', None: 'None', - Session: 'Session' + Session: 'Session', + Client: 'Client' }; Object.freeze(AuthType); @@ -76,6 +77,23 @@ const Auth = { .catch(() => Auth.app(client)); }, + client(client, clientId) { + if (!client.appKey || !client.appSecret) { + return Promise.reject( + new Error('Missing client appKey and/or appSecret' + + ' Use Kinvey.initialize() to set the appKey and masterSecret for the client.') + ); + } + if (!clientId){ + clientId = client.appKey; + } + return Promise.resolve({ + scheme: 'Basic', + username: clientId, + password: client.appSecret + }); + }, + /** * Authenticate through Master Secret. * @@ -160,6 +178,7 @@ export class KinveyRequest extends NetworkRequest { this.properties = options.properties || new Properties(); this.skipBL = options.skipBL === true; this.trace = options.trace === true; + this.clientId = options.clientId; } static execute(options, client, dataOnly = true) { @@ -320,7 +339,7 @@ export class KinveyRequest extends NetworkRequest { // Add or remove the Authorization header if (this.authType) { - // Get the auth info based on the set AuthType + // Get the auth info based on the set AuthType switch (this.authType) { case AuthType.All: promise = Auth.all(this.client); @@ -331,6 +350,9 @@ export class KinveyRequest extends NetworkRequest { case AuthType.Basic: promise = Auth.basic(this.client); break; + case AuthType.Client: + promise = Auth.client(this.client, this.clientId); + break; case AuthType.Master: promise = Auth.master(this.client); break; From 7244ef30b52235ce6cf1815d03b4a7ca3f271646 Mon Sep 17 00:00:00 2001 From: tejasranade Date: Wed, 7 Mar 2018 13:38:01 -0500 Subject: [PATCH 2/2] minor test and error handling improvements --- src/core/identity/mic.spec.js | 4 ++++ src/core/request/network.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/identity/mic.spec.js b/src/core/identity/mic.spec.js index c7653e13d..2c1078c7f 100644 --- a/src/core/identity/mic.spec.js +++ b/src/core/identity/mic.spec.js @@ -204,6 +204,10 @@ describe('MobileIdentityConnect', () => { '/oauth/token', `grant_type=authorization_code&client_id=${client.appKey}&redirect_uri=${encodeURIComponent(redirectUri)}&code=${code}` ) + .basicAuth({ + user: client.appKey, + pass: client.appSecret + }) .reply(200, token, { 'Content-Type': 'application/json; charset=utf-8' }); diff --git a/src/core/request/network.js b/src/core/request/network.js index 62a870f6a..bb5da8f1e 100644 --- a/src/core/request/network.js +++ b/src/core/request/network.js @@ -81,7 +81,7 @@ const Auth = { if (!client.appKey || !client.appSecret) { return Promise.reject( new Error('Missing client appKey and/or appSecret' - + ' Use Kinvey.initialize() to set the appKey and masterSecret for the client.') + + ' Use Kinvey.initialize() to set the appKey and appSecret for the client.') ); } if (!clientId){