Using a console app, how can I log in to Episerver

Vote:
 

Using a console app, how can I log in to Episerver CMS so I can access an API that I need to be logged in for.

I then want to be able to use HttpRequest's to bring back data from the API that needs CMSAdmin credentials for example.

The version we are using is Episerver 7.5 and the authentication is Forms Authentication

#225929
Jul 30, 2020 14:26
Vote:
 

Hi bazzagan,

"Fake" web browser request from console app: you would need to request the login form page (and your console client needds to have cookies enabled) so that you get the needed Episerver CMS cookies (see the link for the cookie names) and then you would do a post with username, password and the needed cookies (the xsrf cookie value needs to be also sent in the hidden field of the form, look the names from the login page html source). if the login succeeds then you have in the response cookies your roles etc and then can call your API wit those cookies and get the OOB Authorize attribute fuinctionality what I assume you are using at the moment). The console app request implementationis then naturally up to you if you will use HttpClient or WebRequest to make the actual requests to the login page.

Another approach might be use some sort of API key that the client sends when requesting data from the API and in your API instead of AuthorizeAttribute you use your custom implementation to validate that the client is allowed to do the request.

#225963
Jul 31, 2020 8:00
Vote:
 

Thanks Antti. That is just what I needed. I grabbed the cookies and posted them with each request using HttpClient and all was happiness. Have a great day :)

#226525
Aug 14, 2020 9:27
Vote:
 

Hi bazzagan, good to hear.

If I may ask one thing, could you mark my reply as answer :D so others know too there is a solution for your question.

#226532
Aug 14, 2020 10:10
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.