c# - Want to Create a Common WebAPI Login That Many Sites Will Use -


we need create simple site authentication/authorization. use latest oauth , owin , microsoft identity. assuming webapi way go new , mvc in general let me know if better way out there.

i have created simple login service web api has account controller. here login action use:

[allowanonymous] public actionresult login(string returnurl) {   viewbag.returnurl = returnurl;   return view(); } 

and here simple client web app call login service app.

public async task<actionresult> index() {   var client = new httpclient();   var response = await client.getasync("http://localhost:19604/account/login");   string thing = await response.content.readasstringasync();    return content(thing); } 

this returns me view wanting email, password, remember me , such. however, buttons not work. when click login button 404 on /account/login. suspect because webapi controller no longer hooked , client side not have account controller.

is return content(thing); causing problem , breaking it? need hard-code actions on login service go specific urls? or wanting not possible?

in end, want login service web api return me credentials/token logged in users claims if had logged in via client app itself.

first, webapi controllers, don't return view. return ihttpactionresult (put in more sensible way, return http codes)

the login button preferably goes login action of account controller in mvc context.

you cannot directly want unless in customised way.

for e.g.

  1. on clicking login button, redirect call private method within controller itself.
  2. call login method of webapi project inside private method.
  3. if login succeeds, (say if http 200 returned), redirect call corresponding mvc controller. if not, (say, on http 404 errors) go custom error page.

or else, can implement custom membership. decorate controller [custommembershipattribute] (here) attribute. see here

as side note: prefer using restsharp rather creating new instance of httpclient , using it. code looks clumsy me ;)


Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -