Skip to content

Commit

Permalink
post publish v2.2.0-beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmantz committed Oct 5, 2016
1 parent a469303 commit c72d09f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/redux-oidc.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-oidc",
"version": "2.2.0-beta.2",
"version": "2.2.0-beta.3",
"description": "A package for managing OpenID Connect authentication in redux apps",
"main": "dist/redux-oidc.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/CallbackComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ class CallbackComponent extends React.Component {
static propTypes = {
successCallback: PropTypes.func.isRequired,
errorCallback: PropTypes.func,
route: PropTypes.string
};

static contextTypes = {
userManager: PropTypes.object
};

componentDidMount() {
this.context.userManager.signinRedirectCallback()
this.context.userManager.signinRedirectCallback(this.props.route)
.then((user) => this.onRedirectSuccess(user))
.catch((error) => this.onRedirectError(error));
}
Expand Down
6 changes: 3 additions & 3 deletions src/oidcMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getUserSuccessCallback(next, userManager, user, triggerAuthFlow,
if (triggerAuthFlow) {
// IF: auth flow should be triggered
userManager.signinRedirect({ data: {
redirectUrl: window.location.href
redirectUrl: window.location.pathname
}
});
} else {
Expand All @@ -45,11 +45,11 @@ export function getUserErrorCallback(error) {

// the middleware creator function
export default function createOidcMiddleware(userManager, shouldValidate, triggerAuthFlow, callbackRoute) {
if (!userManager) {
if (!userManager || !userManager.getUser || !userManager.signinRedirect) {
throw new Error('You must provide a user manager!');
}

if (!callbackRoute) {
if (typeof(callbackRoute) !== 'string') {
throw new Error('You must provide the callback route!');
}

Expand Down
11 changes: 11 additions & 0 deletions tests/callbackComponent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,15 @@ describe('<CallbackComponent />', () => {
expect(() => component.onRedirectError(error)).toThrow(/error/);
expect(removeItemStub.calledWith(STORAGE_KEY)).toEqual(true);
});

it('should call the signinSilentCallback with a route when it has been provided', () => {
const route = '/some/route';
props = { ...props, route };
component = new CallbackComponent(props);
component.context = Object.assign({}, { ...component.context }, { ...contextMock });

component.componentDidMount();

expect(signinRedirectCallbackStub.calledWith(route)).toEqual(true);
});
});
19 changes: 14 additions & 5 deletions tests/oidcMiddleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ describe('createOidcMiddleware()', () => {
let getStateStub;
let action;
let stateMock;
let href = 'http://some.url.com';
let pathname = '/callback';
let callbackRoute = '/callback';

beforeEach(() => {
windowMock = {
location: { href, pathname }
location: { pathname }
};
oldWindow = window;
window = windowMock;
Expand Down Expand Up @@ -97,6 +96,17 @@ describe('createOidcMiddleware()', () => {
expect(nextFunction.length).toEqual(1);
});

it('should throw an error when no user manager has been provided', () => {
expect(() => {createOidcMiddleware(null, null, null, callbackRoute)}).toThrow(/You must provide a user manager!/);
expect(() => {createOidcMiddleware({}, null, null, callbackRoute)}).toThrow(/You must provide a user manager!/);
expect(() => {createOidcMiddleware('userManager', null, null, callbackRoute)}).toThrow(/You must provide a user manager!/);
});

it('should throw an error when no callback route has been provided', () => {
expect(() => {createOidcMiddleware(userManagerMock, null, null, null)}).toThrow(/You must provide the callback route!/);
expect(() => {createOidcMiddleware(userManagerMock, null, null, {})}).toThrow(/You must provide the callback route!/);
});

it('should call the shouldValidate() function with the redux state and dispatched action', () => {
const shouldValidate = sinon.stub();
createOidcMiddleware(userManagerMock, shouldValidate, null, callbackRoute)(storeMock)(nextStub)(action);
Expand Down Expand Up @@ -178,7 +188,7 @@ describe('createOidcMiddleware()', () => {
const result = getUserSuccessCallback(nextStub, userManagerMock, user, true, action);
const stateData = {
data: {
redirectUrl: href
redirectUrl: pathname
}
};

Expand Down Expand Up @@ -230,8 +240,7 @@ describe('createOidcMiddleware()', () => {

windowMock = {
location: {
pathname: '/someRoute',
href
pathname: '/someRoute'
}
};
window = windowMock;
Expand Down

0 comments on commit c72d09f

Please sign in to comment.