Capturing Response URL in case of URL Redirect( Authorization code Grant)


I am trying to make Authorization Grant Flow(OAuth) to an ADFS Server. The first step is to get a Authorization Code from the ADFS(Identity Server)

For example, ADFS Auth Server URL:

The redirect URI is maintained as: “

Whenever, a POST Request is made to the ADFS OAuth Authorization Server on a Browser, it redirects to the REDIRECT_URI with the Authorization Code.

For example, whenever, POST Request to
returns a 302 FOUND and returns a Response Header Cookie.

Then, a GET Request is sent to the same server with the Cookie Received and then it returns a 302 FOUND with the Location and then it redirects to

Then, i will use this authorization code to get the access token.

Now, i am unable to fetch the code from the redirected URI

var data = $.param({
UserName: $scope.UserName,
Password: $scope.Password,
AuthMethod: $scope.AuthMethod

var res = $, data);
res.success(function(data, status, headers, config) {
$scope.result = data;
Now the data field returns the html page of

for example, The code that i wrote to fetch the code( in the field token)

<div id="output></div> <script> var token ='code=')[1]; $(#output).innerHTML = "The Authorization Code is" + token;

I need to handle the 302 Redirect and capture the Location
I was able to do that in c# using Response.ResponseURI field. But, how to achieve that in Angular/Ionic


Can you try this?
$, data);
res.success(function(data, status, headers, config) {

// Check for all the header information in response

// it should be here. If it’s not, check above console log output



Thanks for the reply. But, its not working.Were you able to achieve the Authorization Grant Flow in Ionic.

is giving the below output

headers(‘Location’) is blank
This is the actual output of the Web Page(… )

i have updated the issue with more details