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


#1

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: http://example.adfs.com/oauth/authorize

The redirect URI is maintained as: “http://redirecturi.com

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 http://example.adfs.com/oauth/authorize
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 http://redirecturi.com?code=VMSLSS.3487NDJASDJSDAJJADSD

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 = $http.post(url, data);
res.success(function(data, status, headers, config) {
$scope.result = data;
});
Now the data field returns the html page of http://redirecturi.com

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

<div id="output></div> <script> var token = location.search.split('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


#2

Hello!
Can you try this?
`
$http.post(url, data);
res.success(function(data, status, headers, config) {

// Check for all the header information in response
console.log(headers());

// it should be here. If it’s not, check above console log output
console.log(headers(‘Location’));
});
`


#3

@ekhmoi

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

headers();
is giving the below output

headers(‘Location’) is blank
This is the actual output of the Web Page( www.redirecturi.com?code=23141lasldsadas… )

i have updated the issue with more details

Thanks
Sourav