Giter VIP home page Giter VIP logo

Comments (5)

robertdamphousse-okta avatar robertdamphousse-okta commented on July 19, 2024 1

Hi @danielheth , in its default configuration the AuthJS library does need to use the # fragment. You can configure the callback to be query-parameter based, which would allow you to use the # fragment for your own routing instead. However I'm not sure if this library has property abstracted those configuration options. I'm referring to the responseMode option that is mentioned here:

https://github.com/okta/okta-auth-js#openid-connect-options

from okta-oidc-js.

lboyette-okta avatar lboyette-okta commented on July 19, 2024 1

The OAuth spec requires that only one hash fragment exist.

   The redirection endpoint URI MUST be an absolute URI as defined by
   [RFC3986] Section 4.3.  The endpoint URI MAY include an
   "application/x-www-form-urlencoded" formatted (per Appendix B) query
   component ([RFC3986] Section 3.4), which MUST be retained when adding
   additional query parameters.  The endpoint URI MUST NOT include a
   fragment component.

So you have two options:

  1. Do URL rewrites for your SPA
  2. Create another page that's not part of the SPA that contains your callback logic. This will be your new redirect_uri. Make sure to add this page's url to your list of redirect uris in Okta. Here's what it might look like:
<!-- callback.html -->
<script>
// OIDC variables
var issuer = '## your issuer ##';
var clientId = '## your clientId ##';
var redirectUri = '## your redirect uri (this page) ##';
var redirectAfterSuccess = '## your destination after successful signin ##';

// build an auth client
var client = new OktaAuth({
  url: issuer.split('/oauth2/')[0],
  clientId: clientId
  issuer: issuer,
  redirectUri: redirectUri
});

// parse tokens from the url
client.token.parseFromUrl()
.then(function(tokens) {

  // add tokens to the tokenManager
  for (var t = 0; t < tokens.length; t++) {
    var token = tokens[t];
    if (token.idToken) {
      client.tokenManager.add('idToken', token);
    } else if (token.accessToken) {
      client.tokenManager.add('accessToken', token);
    }
  }

  // redirect when finished
  window.location = redirectAfterSuccess;
})
.catch(function(err) {
  // handle the error
});
</script>

from okta-oidc-js.

danielheth avatar danielheth commented on July 19, 2024

I was able to track down that you're using the localStorage browser functionality to store tokens... i tested it by using:

localStorage.setItem('hello', '1234');
console.log('hello:', localStorage.getItem('hello'));

And didn't have any troubles.. so somewhere in your code... localStorage isn't working correctly.

from okta-oidc-js.

danielheth avatar danielheth commented on July 19, 2024

Finally got a very simple angular2 app working... but the instant i enabled HashLocationStrategy (https://angular.io/api/common/HashLocationStrategy) things blew up.

I believe it is because this line assumes there will only be one hash (#) within the url... https://github.com/okta/okta-auth-js/blob/f162b052efd664dd0db843032c1970dec4639e66/lib/token.js#L599

from okta-oidc-js.

jmelberg-okta avatar jmelberg-okta commented on July 19, 2024

Closing down this issue due the answers provided. Please reopen is the problem persists.

from okta-oidc-js.

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.