Repository: singingwolfboy/flask-dance

Issue:
The github.access_token return None even if the access token is available
A demonstration is in this app:
https://github.com/giocalitri/flask-dance-github/blob/gdm_test/github.py

After getting the token with the first endpoint, try to GET the second and you will have something like:

```
{
  "access_token": null, 
  "token": {
    "access_token": "XXXXXXXXXXXXXXXXXXXXXXXXXX", 
    "scope": [
      ""
    ], 
    "token_type": "bearer"
  }
}
```

Comments:

Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 35a7a20..840bc74 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -3,7 +3,9 @@ Change Log
 
 unreleased
 ----------
-Nothing yet
+* Accessing the ``access_token`` property on an instance of the
+  ``OAuth2Session`` class will now query the token backend, instead of
+  checking the client on the instance.
 
 0.13.0 (2017-11-12)
 -------------------
diff --git a/flask_dance/consumer/requests.py b/flask_dance/consumer/requests.py
index 6c93abe..cd711a8 100644
--- a/flask_dance/consumer/requests.py
+++ b/flask_dance/consumer/requests.py
@@ -102,6 +102,10 @@ class OAuth2Session(BaseOAuth2Session):
             return True
         return False
 
+    @property
+    def access_token(self):
+        return self.token and self.token.get("access_token")
+
     @property
     def authorized(self):
         """ This is the property used when you have a statement in your code


Test patch:
diff --git a/tests/consumer/test_requests.py b/tests/consumer/test_requests.py
index 7cf3732..1476e87 100644
--- a/tests/consumer/test_requests.py
+++ b/tests/consumer/test_requests.py
@@ -7,11 +7,6 @@ from pkg_resources import parse_version
 import requests_oauthlib
 from flask_dance.consumer.requests import OAuth1Session, OAuth2Session
 
-requires_requests_oauthlib_05 = pytest.mark.skipif(
-    parse_version(requests_oauthlib.__version__) < parse_version('0.5'),
-    reason="requires requests_oauthlib at version 0.5 or higher",
-)
-
 
 FAKE_OAUTH1_TOKEN = {
     "oauth_token": "abcdefg",
@@ -24,14 +19,12 @@ FAKE_OAUTH2_TOKEN = {
 }
 
 
-@requires_requests_oauthlib_05
 def test_oauth1session_authorized():
     bp = mock.Mock(token=FAKE_OAUTH1_TOKEN)
     sess = OAuth1Session(client_key="ckey", client_secret="csec", blueprint=bp)
     assert sess.authorized == True
 
 
-@requires_requests_oauthlib_05
 def test_oauth1session_not_authorized():
     bp = mock.Mock(token=None)
     sess = OAuth1Session(client_key="ckey", client_secret="csec", blueprint=bp)
@@ -48,3 +41,27 @@ def test_oauth2session_not_authorized():
     bp = mock.Mock(token=None)
     sess = OAuth2Session(client_id="cid", blueprint=bp)
     assert sess.authorized == False
+
+
+def test_oauth2session_token():
+    bp = mock.Mock(token=FAKE_OAUTH2_TOKEN)
+    sess = OAuth2Session(client_id="cid", blueprint=bp)
+    assert sess.token == FAKE_OAUTH2_TOKEN
+
+
+def test_oauth2session_unset_token():
+    bp = mock.Mock(token=None)
+    sess = OAuth2Session(client_id="cid", blueprint=bp)
+    assert sess.token == None
+
+
+def test_oauth2session_access_token():
+    bp = mock.Mock(token=FAKE_OAUTH2_TOKEN)
+    sess = OAuth2Session(client_id="cid", blueprint=bp)
+    assert sess.access_token == "deadbeef"
+
+
+def test_oauth2session_unset_access_token():
+    bp = mock.Mock(token=None)
+    sess = OAuth2Session(client_id="cid", blueprint=bp)
+    assert sess.access_token == None