IdentityModel / oidc-token-manager

Apache License 2.0
51 stars 36 forks source link

Extend Sample for External Providers #36

Closed galenp closed 8 years ago

galenp commented 8 years ago

If I recall, IdSvr can pass the user directly through to an external Identity Provider if you pass idp: in the &acr_values on the token request.

For this to work nicely I figure the acr_values need to be set depending on the button clicked on the client.

Unless I'm mistaken I can't see a way to do this nicely in the current sample without a pretty big re-factor because the settings are not an exposed public property and are set on page load. The settings.acr_values would be required to be set based on the button clicked.

One option is to modify the redirectForToken function


///oidc-token-manager.js
TokenManager.prototype.redirectForToken = function (acrValues) {
    var oidc = this.oidcClient;
    oidc._settings.acr_values = acrValues;
    oidc.createTokenRequestAsync().then(function (request) {
        window.location = request.url;
    }, function (err) {
        console.error("TokenManager.redirectForToken error: " + (err && err.message || err || ""));
    });
}

///index.html (HTML)
<button id="tokenFromGoogle">Get Token (Google)</button>

///index.html (JS)
 $("#tokenFromGoogle").click(function () {
  mgr.redirectForToken("idp:Google");
 });

But I'm sure there is a cleaner, nicer way to do this that is perhaps already supported by the library...and was wondering if you guys can direct me to it.

Thanks

galenp commented 8 years ago

Never mind, apparently I can just do this:

///index.html (HTML)

$("#tokenFromGoogle").click(function () {
      mgr._settings.acr_values = "idp:Google";
      mgr.redirectForToken();
 });