Skip to content

Commit

Permalink
Add administratives endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Tavares <christian.tavares@ossystems.com.br>
  • Loading branch information
Christian Tavares authored and otavio committed Nov 29, 2018
1 parent 1121633 commit d79c493
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 8 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ already developed in the following list:
- [ ] Delete a JSON Web Key
- [x] Get consent request information
- [x] Accept an consent request
- [ ] Reject an consent request
- [x] Reject an consent request
- [x] Get an login request
- [x] Accept an login request
- [ ] Reject a login request
- [ ] Lists all consent sessions of a user
- [ ] Revokes all previous consent sessions of a user
- [ ] Revokes consent sessions of a user for a specific OAuth 2.0 Client
- [ ] Logs user out by deleting the session cookie
- [ ] Invalidates a user's authentication session
- [ ] Flush Expired OAuth2 Access Tokens
- [x] Reject a login request
- [x] Lists all consent sessions of a user
- [x] Revokes all previous consent sessions of a user
- [x] Revokes consent sessions of a user for a specific OAuth 2.0 Client
- [x] Logs user out by deleting the session cookie
- [x] Invalidates a user's authentication session
- [x] Flush Expired OAuth2 Access Tokens
- [x] Introspect OAuth2 tokens

## License
Expand Down
52 changes: 52 additions & 0 deletions hydra/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,55 @@ def accept_consent_request(self, challenge, accept_consent_config):
json=accept_consent_config)
if response.ok:
return response.json()

def reject_login_request(self, challenge, reject_login_config):
response = self.request(
'PUT', '/oauth2/auth/requests/login/{}/reject'.format(challenge),
json=reject_login_config)
if response.ok:
return response.json()

def reject_consent_request(self, challenge, reject_consent_config):
response = self.request(
'PUT', '/oauth2/auth/requests/consent/{}/reject'.format(challenge),
json=reject_consent_config)
if response.ok:
return response.json()

def revokes_all_previous_consent_session_user(self, user):
response = self.request(
'DELETE', '/oauth2/auth/sessions/consent/{}'
.format(user))
if response.ok:
response.json()

def revokes_consent_sessions_oAuth2_client(self, user, client):
response = self.request(
'DELETE', '/oauth2/auth/sessions/consent/{}/{}'
.format(user, client))
return response.ok

def lists_all_consent_sessions_user(self, user):
response = self.request(
'GET', '/oauth2/auth/sessions/consent/{}' .format(user))
if response.ok:
return response.json()

def logs_user_out_deleting_session_cookie(self):
response = self.request(
'GET', '/oauth2/auth/sessions/login/revoke')
if response.ok:
return response.json()

def invalidates_users_authentication_session(self, user):
response = self.request(
'DELETE', '/oauth2/auth/sessions/login/{}' .format(user))
print(response)
if response.ok:
return response

def flush_expired_oAuth2_access_tokens(self, not_after):
response = self.request(
'POST', '/oauth2/flush', json=not_after)
if response.ok:
return response
74 changes: 74 additions & 0 deletions tests/test_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,77 @@ def test_can_accept_consent_request(self, request):
'http://localhost:4445/oauth2/auth/requests/consent/{}/accept'
.format(self.challenge),
json=accept_config)

@patch('requests.request')
def test_can_reject_login_request(self, request):
c = Client(**self.data)
reject_config = {
'error': 'test',
'error_debug': 'test',
'error_description': 'test',
'error_hint': 'test',
'status_code': 404
}
c.reject_login_request(self.challenge, reject_config)
request.assert_called_once_with(
'PUT',
'http://localhost:4445/oauth2/auth/requests/login/{}/reject'
.format(self.challenge),
json=reject_config)

@patch('requests.request')
def test_can_reject_consent_request(self, request):
c = Client(**self.data)
reject_config = {
'error': 'test',
'error_debug': 'test',
'error_description': 'test',
'error_hint': 'test',
'status_code': 404
}
c.reject_consent_request(self.challenge, reject_config)
request.assert_called_once_with(
'PUT',
'http://localhost:4445/oauth2/auth/requests/consent/{}/reject'
.format(self.challenge),
json=reject_config)

@patch('requests.request')
def test_can_revokes_all_previous_consent_session_user(self, request):
c = Client(**self.data)
user = 'user'
c.revokes_all_previous_consent_session_user(user)
request.assert_called_once_with(
'DELETE',
'http://localhost:4445/oauth2/auth/sessions/consent/{}'
.format(user)
)

@patch('requests.request')
def test_can_revoke_consent_sessions_oAuth2_client(self, request):
c = Client(**self.data)
user = 'user'
client = c.client
c.revokes_consent_sessions_oAuth2_client(user, c.client)
request.assert_called_with(
'DELETE',
'http://localhost:4445/oauth2/auth/sessions/consent/{}/{}'
.format(user, client))

@patch('requests.request')
def test_can_lists_all_consent_sessions_user(self, request):
c = Client(**self.data)
user = 'user'
c.lists_all_consent_sessions_user(user)
request.assert_called_once_with(
'GET',
'http://localhost:4445/oauth2/auth/sessions/consent/{}'
.format(user))

@patch('requests.request')
def test_can_logs_user_out_deleting_session_cookie(self, request):
c = Client(**self.data)
c.logs_user_out_deleting_session_cookie()
request.assert_called_once_with(
'GET',
'http://localhost:4445/oauth2/auth/sessions/login/revoke')

0 comments on commit d79c493

Please sign in to comment.