Skip to content

Commit

Permalink
fixup! Synced implementation of token_endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tpazderka committed Mar 3, 2019
1 parent 87965a0 commit 3feb5cc
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/test_oauth2_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from oic.oauth2.message import AccessTokenResponse
from oic.oauth2.message import AuthorizationRequest
from oic.oauth2.message import AuthorizationResponse
from oic.oauth2.message import CCAccessTokenRequest
from oic.oauth2.message import ROPCAccessTokenRequest
from oic.oauth2.message import TokenErrorResponse
from oic.oauth2.provider import Provider
from oic.utils.authn.authn_context import AuthnBroker
Expand Down Expand Up @@ -53,6 +55,12 @@
"redirect_uris": [("http://localhost:8087/authz", None)],
'token_endpoint_auth_method': 'client_secret_post',
'response_types': ['code', 'token']
},
"client2": {
"client_secret": "verysecret",
"redirect_uris": [("http://localhost:8087/authz", None)],
'token_endpoint_auth_method': 'client_secret_basic',
'response_types': ['code', 'token']
}
}

Expand Down Expand Up @@ -340,6 +348,53 @@ def test_token_endpoint_unauth(self):
atr = TokenErrorResponse().deserialize(resp.message, "json")
assert _eq(atr.keys(), ['error_description', 'error'])

def test_token_endpoint_client_credentials(self):
authreq = AuthorizationRequest(state="state",
redirect_uri="http://example.com/authz",
client_id="client1")

_sdb = self.provider.sdb
sid = _sdb.access_token.key(user="sub", areq=authreq)
access_grant = _sdb.access_token(sid=sid)
_sdb[sid] = {
"oauth_state": "authz",
"sub": "sub",
"authzreq": "",
"client_id": "client1",
"code": access_grant,
"code_used": False,
"redirect_uri": "http://example.com/authz",
'token_endpoint_auth_method': 'client_secret_basic',
}
areq = CCAccessTokenRequest(grant_type='client_credentials')
authn = 'Basic Y2xpZW50Mjp2ZXJ5c2VjcmV0='
with pytest.raises(NotImplementedError):
self.provider.token_endpoint(request=areq.to_urlencoded(), authn=authn)

def test_token_endpoint_password(self):
authreq = AuthorizationRequest(state="state",
redirect_uri="http://example.com/authz",
client_id="client1")

_sdb = self.provider.sdb
sid = _sdb.access_token.key(user="sub", areq=authreq)
access_grant = _sdb.access_token(sid=sid)
_sdb[sid] = {
"oauth_state": "authz",
"sub": "sub",
"authzreq": "",
"client_id": "client1",
"code": access_grant,
"code_used": False,
"redirect_uri": "http://example.com/authz",
'token_endpoint_auth_method': 'client_secret_basic',
}
areq = ROPCAccessTokenRequest(grant_type='password', username='client1', password='password')
pytest.set_trace()
authn = 'Basic Y2xpZW50Mjp2ZXJ5c2VjcmV0='
with pytest.raises(NotImplementedError):
self.provider.token_endpoint(request=areq.to_urlencoded(), authn=authn)

@pytest.mark.parametrize("response_types", [
['token id_token', 'id_token'],
['id_token token']
Expand Down

0 comments on commit 3feb5cc

Please sign in to comment.