0

Currently, this is the format of Owin response :

{
    access_token: "qefelgrebjhzefilrgo4583535",
    token_type: "bearer",
    expires_in: 59
}

But all the other response from my web api is in this format :

{
    status: 200,
    data: {id = 1, name = 'test'}
}

As we can see data is a member of the response JSON and accessible by using response.data.

So the question now is how can I format my owin authenticator response to look like this.

{
    data : {
         access_token: "qefelgrebjhzefilrgo4583535",
         token_type: "bearer",
         expires_in: 59    
    }

}

From this, in my interceptor i can just return response.data regardless if it is a normal request or a token-authentication request.

Currently i have this implementation to check if the response is from token or from a normal request and I didn't like it.

RestangularConfigurer.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
           if (url.indexOf('token'))
               return response;
           else 
                return response.data;
        });
Anonymous Duck
  • 2,942
  • 1
  • 12
  • 35

1 Answers1

0

No, I don't think you can. The OAuth response is built internally and you should stick with that format.

There is also another answer about this, which is quite a similar problem. You can always build a new OAuth provider from sratch, but I think it's a bit overkill.

Anyway, if the problem is in the JS part and you don't like to check for "token" string, you can try this way:

RestangularConfigurer.addResponseInterceptor(function (data, operation, what, url, response, deferred) {
       if (response.data !== undefined)
           return response.data;
       else return response;
    });
Luca Ghersi
  • 3,261
  • 18
  • 32
  • the if condition is the same intent with the above and about the link i already used token endpoint to add additional params.\ – Anonymous Duck Mar 24 '16 at 04:14