Giter Site home page Giter Site logo

Comments (13)

maxmantz avatar maxmantz commented on September 28, 2024 1

Has triggerAuthFlow always been false in your middleware creator before? It is true in your oidc settings. The user state gets defined automatically when it is set to true in the middleware. If it is false, nothing gets passed by default and the user's state is undefined. You need to call something like this manually when your login gets triggered:

userManager.signinRedirect({
    data: {
        redirectUrl: '/myRedirectUrl'
    }
})

Try switching it to true like this and see if it works:
const oidcMiddleware = createOidcMiddleware(userManager, () => true, true, '/callback');

from redux-oidc.

maxmantz avatar maxmantz commented on September 28, 2024

What version are you using? What are the steps to reproduce this issue? What do your settings look like (for both middleware and callback component)?

from redux-oidc.

pekkah avatar pekkah commented on September 28, 2024

Just upgraded to latest v2.2.0-beta.1

from redux-oidc.

pekkah avatar pekkah commented on September 28, 2024

OIDC config

 oidc: {
    client_id: '...',
    redirect_uri: 'http://localhost:8000/callback',
    response_type: 'id_token token',
    scope: 'openid ...',
    authority: '....',
    silent_redirect_url: 'http://localhost:8000/silent_renew.html',
    automaticSilentRenew: false,
    filterProtocolClaims: true,
    loadUserInfo: true,
    acr_values: '...',
    triggerAuthFlow: true
  }

Callpage page callback

 // define a success callback which receives the signed in user & handles redirection
  successCallback = (user) => {
    // the user object gets the browser's URL before
    // redirection was triggered passed into its state
    // when triggerAuthFlow is set to `true`

    // if state is somehow corrupted on back and forward were pressed redirect to root
    if (user == null || user.state == null || user.state.redirectUrl == null) {
      const location = config.basePath;
      window.location.href = location;
      return;
    }

    // get the original url before redirect
    const urlBeforeRedirection = user.state.redirectUrl;

    // should use the following but it will throw an security exception
    // this.props.dispatch(push('/'));

    // ugly redirect with flickering
    window.location = urlBeforeRedirection;
  };

from redux-oidc.

maxmantz avatar maxmantz commented on September 28, 2024

There are changes to the middleware creator function call because of an issue (#9) reported yesterday. The signature of the function has changed.

Please see the wiki and the middleware creator function call in the example app.

My guess is that the change to triggerAuthFlow has been causing this. It is now undefined by default. You have to set it to true manually to get it to work.

Please also make sure to pass in the callbackRoute to the middleware creator function.

from redux-oidc.

pekkah avatar pekkah commented on September 28, 2024

Yep, I read the wiki before upgrade.

// oidc
const oidcMiddleware = createOidcMiddleware(userManager, () => true, false, '/callback');

from redux-oidc.

pekkah avatar pekkah commented on September 28, 2024

Hmm, which setting will it use then? The one coming from the configuration I pass to userManager {.., triggerAuthFlow: true } or the setting I pass to createOidcMiddlware as parameter?

from redux-oidc.

pekkah avatar pekkah commented on September 28, 2024

Sorry it seems that I misplaced the triggerAuthFlow first time to config I pass the userManager. Don't know where I got that part. Moving it to be passed as parameter to createOidMiddlware instead.

from redux-oidc.

maxmantz avatar maxmantz commented on September 28, 2024

The userManager does not have a triggerAuthFlow setting. This is a flag for the middleware only.

If it is true the middleware automatically redirects to the OIDC provider when the user is expired.

If false, the user in the reducer gets cleared, but no redirect happens - for rendering a custom login screen for example, just like in the sample app. You will have to manually call the userManager.signinRedirect(state) function as described above to pass in the redirectUrl manually (as an onClick handler for a Login button for example).

from redux-oidc.

pekkah avatar pekkah commented on September 28, 2024

Yes, I found the reason. We had a handler for doing redirect to auth when we get a unauthorized response from API call. This was firing up at the same time as the trigger auth flow was triggered.

from redux-oidc.

maxmantz avatar maxmantz commented on September 28, 2024

Glad you were able to resolve the issue.

from redux-oidc.

dantovbein avatar dantovbein commented on September 28, 2024

Hi @maxmantz ,I have a similar error when I'm trying to login through SSO (OneLogin platform) but I cannot find the solution. It the user is not logged or the session is expired it should be redirected to https://jamcity.onelogin.com/oidc/auth?client_id=7e640670-0f7a-0136-512f-06041460d132115152&nonce=ed6dafde735a020192d0ef2f60377da7&redirect_uri=https%3A%2F%2Fgsconfigv2.jamcity.com%2Fcallback&response_type=id_token&scope=openid&state=b9dcfbfc703dfa199f30572b7ac28f9e

The redirect_uri is working as expected (/callback) and to the success function, but when I log the response in successCallback I get this error:

index.js:56 Error: No matching state found in storage
    at oidc-client.min.js:1

According to your documentation https://github.com/maxmantz/redux-oidc I've installed these modules:

"redux-oidc": "^3.0.0-beta.16",
"oidc-client": "^1.4.1",
"oidc-client-fetch": "^1.2.2-fetch1",

Index.js

<Provider store={Store}>
    <OidcProvider store={Store} userManager={userManager}>
      <Router>
        <div>
          <Switch>
             <Route path={`/callback`} component={ CallbackPage } />
             <Route path={`/`} component={ App } />
            </Switch>
        </div>
      </Router>
    </OidcProvider>
</Provider>

user-manager

import { createUserManager } from "redux-oidc";
const clientId = "7e640670-0f7a-0136-512f-06041460d132115152";
export const baseUrl = `${window.location.protocol}//${window.location.hostname}:${window.location.port}`;

const userManagerConfig = {
  authority: 'https://******.onelogin.com/oidc/auth',
  client_id: clientId,
  redirect_uri: `${baseUrl}callback`,
  response_type: 'id_token token',
  scope: 'openid profile',
  post_logout_redirect_uri: `${baseUrl}/login`,
  silent_redirect_uri: `${baseUrl}/silent_renew.html`,
  automaticSilentRenew: true,
  filterProtocolClaims: true,
  loadUserInfo: true
};

const userManager = createUserManager(userManagerConfig);
export default userManager;

Store:

imports ....

const loggerMiddleware = store => next => action => {
  console.log("Action type:", action.type);
  console.log("Action payload:", action.payload);
  console.log("State before:", store.getState());
  next(action);
  console.log("State after:", store.getState());
};
const middleware = applyMiddleware(loggerMiddleware, thunk, promise);
const oidcMiddleware = createOidcMiddleware(userManager, () => true, true, `${baseUrl}callback`);
const Store = createStore(
  reducers,
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__(),
  middleware,
  oidcMiddleware
);
console.log(window.sessionStorage); // Storage {length: 0}
console.log('1', window.localStorage); // 1 Storage {length: 0}
loadUser(Store, userManager);
console.log('2', window.localStorage); // 2 Storage {length: 0}
console.log(window.sessionStorage); // Storage {length: 0}
export default Store;

And this is the log (all is undefined)
store.js:13 Action type: redux-oidc/LOADING_USER
store.js:14 Action payload: undefined
store.js:13 Action type: redux-oidc/USER_EXPIRED
store.js:14 Action payload: undefined

I also tried with a login button through

userManager.signinRedirect();

But I get this error

oidc-client.min.js:1 GET https://*****.onelogin.com/oidc/auth/.well-known/openid-configuration 404 (Not Found)
login:1 Failed to load https://jamcity.onelogin.com/oidc/auth/.well-known/openid-configuration: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://gsconfigv2.jamcity.com' is therefore not allowed access. The response had HTTP status code 404.
oidc-client.min.js:1 Uncaught (in promise) Error: Network Error
    at XMLHttpRequest.o.onerror (oidc-client.min.js:1)

Any idea??

from redux-oidc.

maxmantz avatar maxmantz commented on September 28, 2024

You don't need oidc-client-fetch if you are using oidc-client-js. oidc-client-fetch is required when running SSR, or your SSR setup doesn't work with the classic oidc-client.

from redux-oidc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.