How do i test an application which uses OWIN login

Copper Contributor

Hi,

I have built a web application that usesOWIN security to authenticate users againt Azure Active Directory. I have added the re-direct URL to Azure so that after successful authentication it goes to the live website. 

This all works as expected.

If i want to add and test new features to the site i use Visual studio to add the code, but when i run from VS it performs the authentication and then re-directs to the live site, not running the additional code.

How do i set it up to re-direct back to the test version running in VS?

thanks

Gareth

5 Replies
Hello Gareth,
You will need to specify the re-direct to your local endpoint. In case you are not aware, the redirect happens at the client (browser) so a local reference (for example, https://localhost:7071/mywebsite) is ok.

You will also need to add teh redirect url in your application registration in AAD.
Hi,

if i add it against my application registration in AAD then it still goes to the first re-direct which is the live version.
i need to add something in my VB project?

thanks

Gareth
Yes, you do. The redirect information is in the URL that your application sends to AAD. In my words, your local application on your pc constructs a URL for AAD. That contains who the application is including what location (url) AAD should send the browser back to once AAD is done authenticating the user.

This means your application needs to add the redirect url in the message. Your VB is already doing this and most likely it is in a configuration file. Have a search for the url in your code base. You might get lucky, find the value and simply be able to replace it with your local. Just don't forget to reverse the change before submitting your changes :)
i have been through the code, the vbproj, the sln and applicationhost.config and cannot see any mention of the live server
Hello Gareth,
I primarily work in c# and have not touched VB since the early 2000s. I see a good resource of examples at https://www.example-code.com/vbnet/oauth2.asp

One thing that is interesting, is the examples use json files for the configuration. This makes me think in your situation the configuration might be coming from a file or database of some kind.

Another good example: https://www.gemboxsoftware.com/email/examples/authenticate-using-oauth-c-sharp-vb/109

Unfortunately my only suggestion is keep searching. Keywords like Http, HttpWebRequest. And you might get lucky depending on who wrote the code with words like oauth and redirect.