Quantcast
Channel: Azure Active Directory forum
Viewing all articles
Browse latest Browse all 16000

WAAD Oauth Refresh tokens expiration

$
0
0

HI All

I am working on a mobile HTML5 application running on Windows Phone using Phonegap. I want to use WAAD for directory authentication and OAuth for token handling. I have setup everything and it is working great. I login to the application, get a redirect to WAAD which redirects me to the on premise STS. I login get redirected to waad, get a OAuth token signed by azure. This token consists of a Access_token and a refresh_token. When the access_token is expired, I want to use the refresh token to get a new Access_token and refresh_token. This is were I have some problems. When the access_token expires, it seems like the refresh_token also expires. When I use the refresh_token to get a new access token, I get an error from WAAD stating something like "grant_type invalid or expired". I thought the refresh_tokens were valid for about 60 days. Can someone tell me how to use the refresh_tokens to get a new access_token using JQUery? I have the following code to use the refresh token to get the new oauth token (part of the code):

 

 getAccessTokenByRefreshToken: function () {
        console.log("Refreshing token by refresh token");
        var refreshToken = this.getRefreshToken();
        var clientID = this._clientID;

        console.log("Refresh token is : |" + refreshToken + "|");
        console.log("Client_id : " + clientID);

        if (refreshToken != "") {
            $.mobile.loading('show', {
                text: "Authenticatie",
                textVisible: "true",
                theme: "c"
            });

            var tokenUrl = "https://login.windows.net/common/oauth2/token";
            var request = $.ajax({
                url: tokenUrl,
                contentType: "application/x-www-form-urlencoded",
                type: "POST",
                crossDomain: true,
                    data: {
                    grant_type: "refresh_token",
                    refresh_token: refreshToken,
                    client_id: this._clientID,
                        resource: encodeURI(this._resource)
                }
            }).done(function (e) {
                console.log("Saving new token on local storage");
                console.log("Response from refresh token (access token): " + e.access_token);
                console.log("Response from refresh token (refresh token): " + e.refresh_token);
                console.log("Response from refresh token (token type): " + e.token_type);

                _authenticationModule.saveTokenOnLocalStorage(e);
                $.event.trigger({
                    type: "TokenRefreshDone"
                });
                $.mobile.loading('hide');
            }).fail(function (jqXHR, textStatus, errorThrown) {
                console.log("Unable to get new token by refresh token :" + jqXHR.responseText + ". Status: " + textStatus + " Error: " + errorThrown);
                $.mobile.loading('hide');
                // _authenticationModule.removeToken();
                $.event.trigger({
                    type: "TokenRefreshFailed"
                });
            });
        }
    },

Hope someone can help me out so we can use the refresh tokens to get a new access token.

Patrick


Viewing all articles
Browse latest Browse all 16000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>