Skip to content

Commit

Permalink
Fixing oauth login
Browse files Browse the repository at this point in the history
  • Loading branch information
jaesivsm committed Jun 18, 2024
1 parent c0a77a7 commit 7922761
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 119 deletions.
14 changes: 4 additions & 10 deletions jarr/api/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from datetime import datetime, timedelta, timezone
from datetime import datetime, timezone

from flask import render_template
from flask_jwt_extended import (create_access_token, create_refresh_token,
Expand All @@ -9,7 +9,7 @@
from jarr.bootstrap import conf
from jarr.controllers import UserController
from jarr.lib import emails
from jarr.lib.utils import utc_now
from jarr.lib.utils import get_auth_expiration_delay, utc_now
from jarr.metrics import SERVER
from werkzeug.exceptions import BadRequest, Forbidden

Expand Down Expand Up @@ -45,12 +45,6 @@
)


def _get_declared_expiration_delay(factor=3 / 4) -> str:
declared_delay_sec = conf.auth.expiration_sec * factor
declared_delay = datetime.utcnow() + timedelta(seconds=declared_delay_sec)
return declared_delay.replace(tzinfo=timezone.utc).isoformat()


@auth_ns.route("")
class LoginResource(Resource):
@staticmethod
Expand All @@ -77,7 +71,7 @@ def post():
return {
"access_token": f"Bearer {access_token}",
"refresh_token": f"Bearer {refresh_token}",
"access_token_expires_at": _get_declared_expiration_delay(),
"access_token_expires_at": get_auth_expiration_delay(),
}, 200


Expand All @@ -98,7 +92,7 @@ def post():
SERVER.labels(method="get", uri="/auth/refresh", result="2XX").inc()
return {
"access_token": f"Bearer {access_token}",
"access_token_expires_at": _get_declared_expiration_delay(),
"access_token_expires_at": get_auth_expiration_delay(),
}, 200


Expand Down
Loading

0 comments on commit 7922761

Please sign in to comment.