Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes added to challenge response #1422

Merged
merged 1 commit into from
May 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions server/api/pam_websso.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from datetime import timedelta

import qrcode
import base64
from flasgger import swag_from
from flask import Blueprint, request as current_request, current_app, session
from werkzeug.exceptions import NotFound, Forbidden, HTTPException
Expand Down Expand Up @@ -143,19 +144,29 @@ def start():
logger.debug(f"PamWebSSO user {user.uid if user else None} new session")
url = f"{current_app.app_config.base_url}/weblogin/{service.abbreviation}/{pam_sso_session.session_id}"

qr = qrcode.QRCode()
qr = qrcode.QRCode(border=0)
qr.add_data(url)

# ASCII QRCode
f = io.StringIO()
qr.print_ascii(out=f, invert=True)
f.seek(0)

qr_code = f.read()

return {"result": "OK",
"session_id": pam_sso_session.session_id,
"challenge": f"Please sign in to: {url}\n{qr_code}",
"cached": False}, 201
qr_code_ascii = f.read()

# Base64 PNG QRCode
png = io.BytesIO()
qr.make_image().save(png, format="PNG")
qr_code_png = base64.b64encode(png.getvalue()).decode()

return {
"result": "OK",
"cached": False,
"session_id": pam_sso_session.session_id,
"challenge": f"Please sign in to: {url}\n{qr_code_ascii}",
"url": f"{url}",
"qr_code_ascii": f"{qr_code_ascii}",
"qr_code_png": f"{qr_code_png}"
}, 201


@pam_websso_api.route("/check-pin", methods=["POST"], strict_slashes=False)
Expand Down
Loading