0

I am trying to implement server for issuing web tokens using ASP.NET WebApi. I've found great tutorial on how to do this step by step, and everything is working fine, except I need to change some values in HTTP response.

This is a picture of a call where user credentials are checked and if user exists in database he gets token, if he doesn't he gets HTTP 401 Error.

enter image description here

Here is also closer picture of body of response, cause it is too small on previous picture:

enter image description here

My question is: Is there any chance to change name of access_token property inside returned JSON to auth_token. I need to use different name because, later in the project I will have one more token and it's name has to be access_token too. My second question is: Can I changed date format for .issued and .expires properties? For example to yyyy-MM-dd?

I've used this tutorial http://bitoftech.net/2014/06/01/token-based-authentication-asp-net-web-api-2-owin-asp-net-identity/

So the code is exact same. I am trying to track creation of response with debugger, but I don't have clear vision where it could be. I guess it is inside of SimpleAuthorizationServerProvider class, but I can't find explicit setup of this properties anywhere in project, so I guess that response creates automatically.

12
  • I have not done this before but you could consider transforming the response before its sent to the client? Commented Feb 25, 2015 at 7:55
  • @Intrepid The problem is that I've never used security in WebApi(or WebApi), and I'm not sure how or where to do that...:( Commented Feb 25, 2015 at 7:56
  • All the information is being created by something that is creating Claims... so look for that. It will be doing a context.Validated. Its all about setting up the Identity. Commented Feb 25, 2015 at 8:07
  • @CallumLinington No, I don't want to change it in JavaScript, that has no use at all... I want to find out how to change it in WebApi before it is send to client... Commented Feb 25, 2015 at 8:08
  • Why do you want to change the names of these properties? If they are part of OAuth, they are expected to have these specific names and formats. They aren't meant for display Commented Feb 25, 2015 at 8:09

1 Answer 1

1

While changing the name or the format of the standard token response parameters is definitely not a good idea, here's a way to do it anyway: https://stackoverflow.com/a/28683971/542757

Basically, you'll have to use the TokenEndpointResponse notification and provide your own JSON payload. Sadly, there's a bug that prevents it from working with the OAuth2 authorization server built in Katana 3. You can take a look at a fork I developed with @manfredsteyer ; it includes a fix that allows this kind of scenario: https://github.com/aspnet-contrib/AspNet.Security.OpenIdConnect.Server/tree/dev

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.