0

I'm trying to log in and register with external authentication using MVC5, web api 2 and templates from it. I don't know how to do it. I read asp.net web api 2: how to login with external authentication services?.

When I call

GET /api/Account/ExternalLogins?returnUrl=%2F&generateState=true

response is

{
    "Name": "Facebook",
    "Url": "/api/Account/ExternalLogin?provider=Facebook&
            response_type=token&
            client_id=self&redirect_uri=http%3A%2F%2Flocalhost%3A6685%2F&
            state=Yj1...hU1",
    "State": "Yj1...hU1"
}

(I don't know what is State for) Then i can use the Url above (authentication is with cookies) and response is OK html status and some html page (i dont know why)

This call

GET /api/Account/UserInfo

response info with null loginProvider.

I want to register user with FB or Google, so i need token, but i don't know whitch access_token and how can i get it. In example (link above) is this:

POST /api/Account/RegisterExternal
Authorization: Bearer VPcd1RQ4X... (access_token from url)
Content-Type: application/json
{"UserName":"myusername"}

but what is

access_token from url ?

So, my questions are:

How can I external register / login with web api 2 templates?

What is State for? (seems like useless)

Community
  • 1
  • 1
Gandalf
  • 120
  • 1
  • 2
  • 7

1 Answers1

0

External login is Web Api is supported out of the box and can be easily plugged in using the Owin pipeline. Gettting the access token and performing all the oauth related calls are done by the Facebook Owin Provider.

You can find a sample of facebook login with a web site here

Rahul P Nath
  • 324
  • 4
  • 9