-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Expose QR code helper explicitly. This simplifies making use of it without having access to a client instance. * Update README.rst - use pytest instead of py.test pytest is the "new" name :) * Version 1.0.1 - Docfix and QR method separate --------- Co-authored-by: David Svenson <davidsvenson@outlook.com> Co-authored-by: Andreas Pelme <andreas@pelme.se>
1 parent
16039a3
commit 1d89b37
Showing
6 changed files
with
40 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import hashlib | ||
import hmac | ||
import time | ||
from datetime import datetime | ||
from math import floor | ||
|
||
|
||
def generate_qr_code_content(qr_start_token: str, start_t: [float, datetime], qr_start_secret: str) -> str: | ||
"""Given QR start token, time.time() or UTC datetime when initiated authentication call was made and the | ||
QR start secret, calculate the current QR code content to display. | ||
""" | ||
if isinstance(start_t, datetime): | ||
start_t = start_t.timestamp() | ||
elapsed_seconds_since_call = int(floor(time.time() - start_t)) | ||
qr_auth_code = hmac.new( | ||
qr_start_secret.encode(), | ||
msg=str(elapsed_seconds_since_call).encode(), | ||
digestmod=hashlib.sha256, | ||
).hexdigest() | ||
return f"bankid.{qr_start_token}.{elapsed_seconds_since_call}.{qr_auth_code}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters