Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLIBZ-2422: Validate MIC RedirectUri #283

Merged
merged 2 commits into from
Apr 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/core/identity/mic.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export class MobileIdentityConnect extends Identity {
}

login(redirectUri, authorizationGrant = AuthorizationGrant.AuthorizationCodeLoginPage, options = {}) {
if (!isString(redirectUri)) {
return Promise.reject(new KinveyError('A redirectUri is required and must be a string.'));
}

let clientId = this.client.appKey;

if (isString(options.micId)) {
Expand Down Expand Up @@ -206,7 +210,7 @@ export class MobileIdentityConnect extends Identity {
password: options.password,
scope: 'openid'
},
followRedirect: false
followRedirect: false
});
return request.execute();
}).then((response) => {
Expand Down Expand Up @@ -253,7 +257,7 @@ export class MobileIdentityConnect extends Identity {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
authType: AuthType.Client,
authType: AuthType.Client,
url: url.format({
protocol: this.client.micProtocol,
host: this.client.micHost,
Expand Down
31 changes: 30 additions & 1 deletion src/core/identity/mic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import nock from 'nock';
import url from 'url';
import { MobileIdentityConnect, AuthorizationGrant } from './mic';
import { InsufficientCredentialsError, MobileIdentityConnectError, KinveyError } from '../errors';
import { Client } from '../client';
import { randomString } from '../utils';
import { NetworkRack } from '../request';
import { NodeHttpMiddleware } from '../../node/http';
Expand Down Expand Up @@ -66,6 +65,36 @@ describe('MobileIdentityConnect', () => {

describe('login()', () => {
describe('AuthorizationGrant.AuthorizationCodeAPI', () => {
it('should fail if a redirect uri is not provided', () => {
const username = 'test';
const password = 'test';
const mic = new MobileIdentityConnect();
return mic.login(null, AuthorizationGrant.AuthorizationCodeAPI, { username, password })
.then(() => {
throw new Error('This test should fail');
})
.catch((error) => {
expect(error).toBeA(KinveyError);
expect(error.message).toEqual('A redirectUri is required and must be a string.');
});
});

it('should fail if redirect uri is not a string', () => {
it('should fail if a redirect uri is not provided', () => {
const username = 'test';
const password = 'test';
const mic = new MobileIdentityConnect();
return mic.login({}, AuthorizationGrant.AuthorizationCodeAPI, { username, password })
.then(() => {
throw new Error('This test should fail');
})
.catch((error) => {
expect(error).toBeA(KinveyError);
expect(error.message).toEqual('A redirectUri is required and must be a string.');
});
});
});

it('should fail with invalid credentials', () => {
const tempLoginUriParts = url.parse('https://auth.kinvey.com/oauth/authenticate/f2cb888e651f400e8c05f8da6160bf12');
const username = 'test';
Expand Down