Facebook login using OAuth 2.0

后端 未结 4 1025
Happy的楠姐
Happy的楠姐 2021-01-15 10:20
  1. I want people to log in to my site with their Facebook accounts.
  2. I need to pull some info from their Facebook profile and add it to my site\'s database
4条回答
  •  悲&欢浪女
    2021-01-15 11:09

    In OAuth 2.0 with facebook, the overall concept is simple as follows.

    Step 1. Obtain "Authorization Code" by a GET request

    request URI: https://www.facebook.com/dialog/oauth
    Params:
        response_type=code
        client_id={add your "App id" got by registering app}
        redirect_uri={add redirect uri defined at the registration of app}
        scope={add the scope needed in your app}
    Headers: None
    

    Step 2. Obtain the "Access Token" by sending the authorization code as a POST request

    request URI: https://graph.facebook.com/oauth/access_token
    Params:
        grant_type=authorization_code
        client_id=
        redirect_uri=
        code=
    Headers:
        Authorization:Basic encode  with base64 
        Content-Type:application/json
    

    Step 3. Use the access token got from above step and retrieve user resources

提交回复
热议问题