class_docstr: Facebook authentication using the new Graph API and OAuth2.
class_docstr_tok: ["Facebook","authentication","using","the","new","Graph","API","and","OAuth2","."]
docstr: Handles the login for the Facebook user, returning a user object.
  
  Example usage:
  
  .. testcode::
  
      class FacebookGraphLoginHandler(tornado.web.RequestHandler,
                                      tornado.auth.FacebookGraphMixin):
        @tornado.gen.coroutine
        def get(self):
            if self.get_argument("code", False):
                user = yield self.get_authenticated_user(
                    redirect_uri='/auth/facebookgraph/',
                    client_id=self.settings["facebook_api_key"],
                    client_secret=self.settings["facebook_secret"],
                    code=self.get_argument("code"))
                # Save the user with e.g. set_secure_cookie
            else:
                yield self.authorize_redirect(
                    redirect_uri='/auth/facebookgraph/',
                    client_id=self.settings["facebook_api_key"],
                    extra_params={"scope": "read_stream,offline_access"})
  
  .. testoutput::
     :hide:
  
  This method returns a dictionary which may contain the following fields:
  
  * ``access_token``, a string which may be passed to `facebook_request`
  * ``session_expires``, an integer encoded as a string representing
    the time until the access token expires in seconds. This field should
    be used like ``int(user['session_expires'])``; in a future version of
    Tornado it will change from a string to an integer.
  * ``id``, ``name``, ``first_name``, ``last_name``, ``locale``, ``picture``,
    ``link``, plus any fields named in the ``extra_fields`` argument. These
    fields are copied from the Facebook graph API `user object <https://developers.facebook.com/docs/graph-api/reference/user>`_
  
  .. versionchanged:: 4.5
     The ``session_expires`` field was updated to support changes made to the
     Facebook API in March 2017.
docstr_tok: ["Handles","the","login","for","the","Facebook","user",",","returning","a","user","object",".","Example","usage",":","..","testcode",":",":","class","FacebookGraphLoginHandler","(","tornado.web.RequestHandler",",","tornado.auth.FacebookGraphMixin",")",":","@","tornado.gen.coroutine","def","get","(","self",")",":","if","self.get_argument","(","``","code","''",",","False",")",":","user","=","yield","self.get_authenticated_user","(","redirect_uri='\/auth\/facebookgraph\/","'",",","client_id=self.settings","[","``","facebook_api_key","''","]",",","client_secret=self.settings","[","``","facebook_secret","''","]",",","code=self.get_argument","(","``","code","''",")",")","#","Save","the","user","with","e.g",".","set_secure_cookie","else",":","yield","self.authorize_redirect","(","redirect_uri='\/auth\/facebookgraph\/","'",",","client_id=self.settings","[","``","facebook_api_key","''","]",",","extra_params=","{","``","scope","''",":","``","read_stream",",","offline_access","''","}",")","..","testoutput",":",":",":","hide",":","This","method","returns","a","dictionary","which","may","contain","the","following","fields",":","*","``","access_token","``",",","a","string","which","may","be","passed","to","`","facebook_request","`","*","``","session_expires","``",",","an","integer","encoded","as","a","string","representing","the","time","until","the","access","token","expires","in","seconds",".","This","field","should","be","used","like","``","int","(","user","[","'session_expires","'","]",")","``",";","in","a","future","version","of","Tornado","it","will","change","from","a","string","to","an","integer",".","*","``","id","``",",","``","name","``",",","``","first_name","``",",","``","last_name","``",",","``","locale","``",",","``","picture","``",",","``","link","``",",","plus","any","fields","named","in","the","``","extra_fields","``","argument",".","These","fields","are","copied","from","the","Facebook","graph","API","`","user","object","<","https",":","\/\/developers.facebook.com\/docs\/graph-api\/reference\/user",">","`","_","..","versionchanged",":",":","4.5","The","``","session_expires","``","field","was","updated","to","support","changes","made","to","the","Facebook","API","in","March","2017","."]
code: def get_authenticated_user(
      self,
      redirect_uri,
      client_id,
      client_secret,
      code,
      callback,
      extra_fields=None,
  ):
      """Handles the login for the Facebook user, returning a user object.
  
      Example usage:
  
      .. testcode::
  
          class FacebookGraphLoginHandler(tornado.web.RequestHandler,
                                          tornado.auth.FacebookGraphMixin):
            @tornado.gen.coroutine
            def get(self):
                if self.get_argument("code", False):
                    user = yield self.get_authenticated_user(
                        redirect_uri='/auth/facebookgraph/',
                        client_id=self.settings["facebook_api_key"],
                        client_secret=self.settings["facebook_secret"],
                        code=self.get_argument("code"))
                    # Save the user with e.g. set_secure_cookie
                else:
                    yield self.authorize_redirect(
                        redirect_uri='/auth/facebookgraph/',
                        client_id=self.settings["facebook_api_key"],
                        extra_params={"scope": "read_stream,offline_access"})
  
      .. testoutput::
         :hide:
  
      This method returns a dictionary which may contain the following fields:
  
      * ``access_token``, a string which may be passed to `facebook_request`
      * ``session_expires``, an integer encoded as a string representing
        the time until the access token expires in seconds. This field should
        be used like ``int(user['session_expires'])``; in a future version of
        Tornado it will change from a string to an integer.
      * ``id``, ``name``, ``first_name``, ``last_name``, ``locale``, ``picture``,
        ``link``, plus any fields named in the ``extra_fields`` argument. These
        fields are copied from the Facebook graph API `user object <https://developers.facebook.com/docs/graph-api/reference/user>`_
  
      .. versionchanged:: 4.5
         The ``session_expires`` field was updated to support changes made to the
         Facebook API in March 2017.
      """
      http = self.get_auth_http_client()
      args = {
          "redirect_uri": redirect_uri,
          "code": code,
          "client_id": client_id,
          "client_secret": client_secret,
      }
  
      fields = set(
          [
              "id",
              "name",
              "first_name",
              "last_name",
              "locale",
              "picture",
              "link",
          ]
      )
      if extra_fields:
          fields.update(extra_fields)
  
      http.fetch(
          self._oauth_request_token_url(**args),
          functools.partial(
              self._on_access_token,
              redirect_uri,
              client_id,
              client_secret,
              callback,
              fields,
          ),
      )
  
imports: from __future__ import absolute_import, division, print_function
  import base64
  import binascii
  import functools
  import hashlib
  import hmac
  import time
  import uuid
  from tornado.concurrent import TracebackFuture, return_future, chain_future
  from tornado import gen
  from tornado import httpclient
  from tornado import escape
  from tornado.httputil import url_concat
  from tornado.log import gen_log
  from tornado.stack_context import ExceptionStackContext
  from tornado.util import unicode_type, ArgReplacer, PY3
label_desc: Use image node_id 1 for calling the FacebookGraphMixin obj's underlying member method code with example usage: obj.get_authenticated_user(redirect_uri, client_id, client_secret, code, callback, extra_fields) without return types