Commit Graph

41 Commits

Author SHA1 Message Date
Chris Hill-Scott
b6b9b3b225 Give a more helpful error when token has expired
We’ve seen quite a few developers encounter the `Invalid token: expired`
error message when they’re getting started using the Notify API. When
this happens they either raise a support ticket or ask for help on
Slack.

In every case this has been because the clock on their
machine/environment/container isn’t accurate. The error message doesn’t
help them figure this out.

This commit adds extra detail to the error message so they can fix the
problem without having to come to us for help.
2017-01-17 10:44:00 +00:00
Martyn Inglis
23ca62a7ac Records the service ID if present, or if an ADMIN api call the string admin-api.
this is used later in logging of requests.
2016-11-30 10:59:55 +00:00
Leo Hemsted
95764af6ea Merge pull request #723 from alphagov/active-service
deactivate a service
2016-11-11 15:25:32 +00:00
Rebecca Law
26d6a0c1a9 Merge branch 'master' into change-v2-error-resp 2016-11-10 14:21:20 +00:00
Leo Hemsted
17cf582502 Merge branch 'master' into active-service 2016-11-10 13:54:02 +00:00
Leo Hemsted
abecb5ff98 Merge pull request #726 from alphagov/auth-500
update python client to 2.0.0
2016-11-10 13:47:34 +00:00
Leo Hemsted
e8c3a5cdde add check for inactive services to auth handler
cleaned up some auth code to marginally improve efficiency of error checking
and hopefully make it easier to read

fixed some incorrect auth headers in the deactivate tests
2016-11-10 11:07:12 +00:00
Rebecca Law
346d90e319 update V2 error response to
{status_code: 403,
 errors: [error: AuthError, message: token has expired}]
}
2016-11-09 14:56:54 +00:00
Rebecca Law
78e84801bd Merge branch 'master' into change-v2-error-resp 2016-11-08 15:59:42 +00:00
Chris Hill-Scott
9248e72c50 Make bearer prefix on auth header case insensitive
From a support ticket:

> the "Bearer" prefix on the auth header is case sensitive. Can this be
> made case-insensitive?

Sure can 🙃
2016-11-07 10:49:05 +00:00
Leo Hemsted
f089b75129 update python client to 2.0.0
this is to prevent 500 errors because <2.0.0 raised AssertionError
if supplied JWT tokens were incorrectly formatted

tests added
2016-11-03 17:05:25 +00:00
Rebecca Law
4cb38e2d12 Use status_code in error response.
Remove code.
2016-11-02 14:58:39 +00:00
Rebecca Law
482d10545b Improvements to the tests.
Update AuthError with a to_dict_v2 method.
2016-11-01 10:33:34 +00:00
Rebecca Law
f5aac5796c Improve the error message when the service id is not the right data type.
Improve the error message is the api key is not valid.
2016-09-23 11:07:49 +01:00
Chris Hill-Scott
d44a0b72bb Rewrite authentication error messages more English 2016-09-16 08:57:55 +01:00
Chris Hill-Scott
1ce91997e8 Give specifc error when service doesn’t exist
If you sign a token with a service ID that doesn’t exist (say, for
example, that you get service ID and API key mixed up) then you get
an error saying that “no API keys exist for the service”. This is wrong
because the service doesn’t even exist.

This commit adds:
- code to check if the service does exist
- a specific error message for this case

The check does mean an extra database call to look up the service.
However this only happens _after_ looping through all the API keys. So
it shouldn’t have a performance implication for anyone using a valid API
key.
2016-09-16 08:49:49 +01:00
Rebecca Law
ecd4b76080 Fix bug with expired token error response 2016-07-22 15:10:37 +01:00
Leo Hemsted
3838715077 refactored the requires_auth handler to raise exceptions
hopefully cleans up code flow and readability [a tiny bit].
raise an AuthException in auth.py, and catch it in errors.py to
save on returning error_repsonse values throughout the function
2016-06-30 10:44:21 +01:00
Leo Hemsted
39519e3f36 attach api_key to app
we previously attached the service id and the key's secret
also more refactoring of auth.py
2016-06-30 10:44:21 +01:00
Leo Hemsted
adbe02783d refactor authentication code
moved api_key secret manipulation (generating and getting) into
authentiation/utils, and added a property on the model, to facilitate
easier matching of authenticated requests and the api keys they used
2016-06-30 10:44:21 +01:00
Leo Hemsted
2b645f490a move get_all_notifications_for_service and get_all_notifications_for_job
moved from notifications/rest -> service/rest and job/rest respectively
endpoint routes not affected
removed requires_admin decorator - that should be set by nginx config
as opposed to python code
2016-06-30 10:44:21 +01:00
Rebecca Law
40fa394226 Update auth module to return consistently formed error messages.
We are trying to get all the error messages to return in the following format:
{result: error,
 message: ['what caused error': 'reason for error']
}
2016-06-17 14:22:58 +01:00
Rebecca Law
b53fdf1f3f Update python client to version 1.0.0.
This version of the client removed the request method, path and body from the encode and decode methods.
The biggest changes here is to the unit tests.
2016-05-04 16:08:23 +01:00
Rebecca Law
8c14b5a8ab This pull request fixes a bug in authentication.
If the service does not have any api keys, there would be an error but it was not formed well.
2016-04-29 10:24:02 +01:00
Rebecca Law
282a62e636 Use the new version of the notifications-python-client. This version no longer adds the req and pay to the claims of the jwt.
The change is backward compatible so an older client that sends a jwt with the extra claims will pass authentication.
Once all the clients have been updated to not include the extra claims some updates to exclude them from the method signatures will happen as well.
2016-04-14 18:12:33 +01:00
Rebecca Law
fe9bf13064 Format authentication error messages for the client. 2016-03-14 15:51:04 +00:00
Rebecca Law
5d7b1bc786 Removed DELIVERY_CLIENT_USER_NAME and DELIVERY_CLIENT_SECRET from configs and auth module 2016-03-08 15:27:12 +00:00
Martyn Inglis
c5a993ead1 Fetch endpoints for notifications
- includes check on token type to ensure clients can perform admin style fetches
2016-03-01 13:30:10 +00:00
Martyn Inglis
d38ba0d36a bumped client version 2016-02-09 18:48:02 +00:00
Adam Shimali
0580f5ab06 New endpoint for delivery app to use.
Once removal of code that uses existing alpha is done, then
duplicated code from /notifications/sms and the new endpoint
can be merged.

Job id is now avaiable in notificaiton but is not used yet.
2016-02-08 14:54:15 +00:00
Rebecca Law
416dd00ac8 Added a test for the case when there is no secret for the api client.
Fix codestyle
2016-02-08 11:33:24 +00:00
Rebecca Law
877a8a0411 Added logging for the authentication errors.
Moved the "no api secret" error message to the end and only create it if there are no
api client secrets
2016-02-08 11:10:54 +00:00
Rebecca Law
27a381c3e9 Allow services to have multiple api keys.
/service/<service_id>/api-key/renew has been renamed to /service/<service_id>/api-key
/service/<service_id>/api-key now creates a token and no longer expires the existing api key.
Moved test for this endpoint to it's own file.
2016-01-20 10:57:46 +00:00
Rebecca Law
1db57dca8c Allow for multiple api keys for a service. 2016-01-19 18:25:21 +00:00
Martyn Inglis
7ecede46e5 Merge branch 'master' into proxy-to-alpha
Conflicts:
	config.py
2016-01-19 14:11:20 +00:00
Rebecca Law
d15e68238d Authentication for admin client api calls where a user and service is not required. 2016-01-19 14:01:26 +00:00
Martyn Inglis
346bc9feac Merge branch 'master' into proxy-to-alpha 2016-01-19 13:49:54 +00:00
Martyn Inglis
7b756567af Updated tests for fetch notifications by id, not simply fetch all 2016-01-19 13:45:57 +00:00
Rebecca Law
4fc5c34320 Change Tokens to ApiKey
Added name to ApiKey model
2016-01-19 12:13:47 +00:00
Rebecca Law
0ad292300d Added authorization headers for all requests 2016-01-15 17:02:29 +00:00
Rebecca Law
34693d70af Removed the main package. 2016-01-14 14:28:23 +00:00