0

everyone,

I have a web api with OpenIddict Authentication.

  • Core.Net 2.0 (C#),
  • EntityFrameWorkCore 2.0

I would like to do integration test, but my controllers have Authorize atribute, so I need to have a autenticate user.

For my IT, I am using SQLite has an in-memory mode , docs

I don´t know howto create an user authenticate and retrieve the Token, that I need after to pass to the WebApi call.

Any advice?

Best regards.

Jolynice

jolynice
  • 514
  • 1
  • 8
  • 25

1 Answers1

0

For a complete integration test, you could go with a custom grant type, as used in this other SO thread: Rich Twitter Digits/Google Auth with OpenIdDictServer.

If you simply want to test your [Authorize]-protected actions, it's easier to mock ISecureDataFormat<AuthenticationTicket> and use it to set OAuthValidationOptions.AccessTokenFormat. You can take a look at the aspnet-contrib validation handler tests to see how it could be done using ASP.NET Core's TestServer.

Kévin Chalet
  • 39,509
  • 7
  • 121
  • 131
  • Hi Pinpoint, thanks for the advice. I will try and I will come back to give my feedback. – jolynice Dec 17 '17 at 22:29
  • @jolynice would you able to create integraion test using Open ID authentication ? if yes, can you provide details/. – S2K Nov 01 '18 at 11:53