Skip to content

Commit 46185eb

Browse files
committed
mesh-967: fix issues with sample auth code
1 parent 5506abf commit 46185eb

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @alisonkinloch-nhs @mattmercer-nhs @nhsdigital/mesh-to-cloud-admins
1+
* @alisonkinloch-nhs @matt-mercer @nhsdigital/mesh-to-cloud-admins

specification/mesh-api.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ info:
212212
213213
**Notes**
214214
- the API rejects the request if the `timestamp` supplied is not within 2 hours of the server time
215-
- in the example below `HMACSECRETKEY` has been `[REDACTED]`, this is the 'environment shared secret' which you received as part of creating your mailbox
215+
- in the example below `SHARED_KEY` has been `[REDACTED]`, this is the 'environment shared secret' which you received as part of creating your mailbox
216216
217217
### Example implementation
218218
Here is an implementation of the above in `python3`.
@@ -222,11 +222,11 @@ info:
222222
import uuid
223223
import datetime from hashlib
224224
import sha256
225-
225+
226226
AUTHSCHEMANAME = "NHSMESH " # Note: Space at the end of the schema.
227-
HMACSECRETKEY = "[REDACTED]" # Note: Don't hard code your passwords in a real implementation.
228-
229-
def buildmeshauthorizationheader(mailboxid: str, password: str = "password", nonce: str = None, noncecount: int = 0):
227+
SHARED_KEY = "[REDACTED]" # Note: Don't hard code your passwords in a real implementation.
228+
229+
def build_auth_header(mailbox_id: str, password: str = "password", nonce: str = None, noncecount: int = 0):
230230
""" Generate MESH Authorization header for mailboxid. """
231231
#Generate a GUID if required.
232232
if not nonce:
@@ -239,15 +239,15 @@ info:
239239
hmac_msg = mailbox_id + ":" + nonce + ":" + str(nonce_count) + ":" + password + ":" + timestamp
240240
241241
#HMAC is a standard crypto hash method built in the python standard library.
242-
hash_code = hmac.HMAC(HMAC_SECRET_KEY.encode(), hmac_msg.encode(), sha256).hexdigest()
242+
hash_code = hmac.HMAC(SHARED_KEY.encode(), hmac_msg.encode(), sha256).hexdigest()
243243
return (
244244
AUTH_SCHEMA_NAME # Note: No colon between 1st and 2nd elements.
245245
+ mailbox_id + ":"
246246
+ nonce + ":"
247247
+ str(nonce_count) + ":"
248248
+ timestamp+ ":"
249249
+ hash_code
250-
)
250+
)
251251
```
252252
253253
## MESH API pseudocode

0 commit comments

Comments
 (0)