IdentityModel / oidc-client-js

OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Apache License 2.0
2.43k stars 836 forks source link

angularjs integration #69

Closed peymanebrahimi closed 8 years ago

peymanebrahimi commented 8 years ago

how can we replace this with old oidcTokenmanager in projects like: https://github.com/IdentityManager/IdentityManager/blob/master/source/Core/Assets/Scripts/App/ttIdm.js specially in this section:

            module.factory('idmTokenManager', [
                'OidcTokenManager', '$browser', 'secAppSettings', '$rootScope',
                function (OidcTokenManager, $browser, secAppSettings, $rootScope) {
                    var oauthSettings = {
                        client_id: "spaclient",
                        authority: secAppSettings.identityServerUrl,
                        redirect_uri: window.location.protocol + "//" + window.location.host + $browser.baseHref() + "callback/",
                        post_logout_redirect_uri: window.location.protocol + "//" + window.location.host + $browser.baseHref(),// + "/shell.html",
                        response_type: "id_token token",
                        scope: "openid profile email roles webapi pscope",
                        silent_redirect_uri: window.location.protocol + "//" + window.location.host + $browser.baseHref() + "frame.html",
                        silent_renew: true//default false
                    };
                    var mgr = new OidcTokenManager(oauthSettings);

                    var applyFuncs = [
                            "_callTokenRemoved", "_callTokenExpiring",
                            "_callTokenExpired", "_callTokenObtained",
                            "_callSilentTokenRenewFailed"
                    ];
                    applyFuncs.forEach(function (name) {
                        var tmp = mgr[name].bind(mgr);
                        mgr[name] = function () {
                            $rootScope.$applyAsync(function () {
                                tmp();
                            });
                        }
                    });

                    return mgr;
                }
            ]);

how can it be rewritten?

markphillips100 commented 8 years ago

I have a cordova demo at https://github.com/markphillips100/oidc-cordova-demo which uses angular 1. There's an angular provider https://github.com/markphillips100/oidc-cordova-demo/blob/master/src/Oidc.Demo.Cordova/www/app/js/services/angular-oidc-client.js which is really baked from Brock's and others work. Is that what you are looking for?

Sivalingaamorthy commented 8 years ago

Mark, these link is very helpful, a good start reference for angular, it uses the oidc-client nicely, would love to see updates & fixes.

brockallen commented 8 years ago

Feel free to enhance this for angular2. Provide a link when you have and we can link to it in the docs.

Condor2708 commented 8 years ago

I am using this library in angular js and I am using signInRedirect when app start, I wanna know how to check if the user already has a token using the oidc-client.js library without redirecting to to Identity Server

brockallen commented 8 years ago

@Condor2708 you can use querySessionStatus: https://github.com/IdentityModel/oidc-client-js/wiki