Skip to content

Commit

Permalink
Use HTTP method specific route decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
markhobson committed Oct 25, 2023
1 parent 7801a09 commit a06ae8f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions schemes/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
bp = Blueprint("auth", __name__)


@bp.route("")
@bp.get("")
@inject.autoparams()
def callback(users: UserRepository) -> BaseResponse:
oauth = _get_oauth()
Expand All @@ -36,12 +36,12 @@ def callback(users: UserRepository) -> BaseResponse:
return redirect(url_for("home.index"))


@bp.route("/unauthorized")
@bp.get("/unauthorized")
def unauthorized() -> Response:
return Response(render_template("unauthorized.html"), status=401)


@bp.route("/logout")
@bp.get("/logout")
def logout() -> BaseResponse:
id_token = session["id_token"]
del session["user"]
Expand Down
2 changes: 1 addition & 1 deletion schemes/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
bp = Blueprint("home", __name__)


@bp.route("")
@bp.get("")
@secure
def index() -> str:
return render_template("home.html")
2 changes: 1 addition & 1 deletion schemes/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
bp = Blueprint("start", __name__)


@bp.route("/")
@bp.get("/")
@basic_auth
def index() -> BaseResponse:
if "user" in session:
Expand Down
4 changes: 2 additions & 2 deletions schemes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_all(self) -> List[User]:
bp = Blueprint("users", __name__)


@bp.route("", methods=["POST"])
@bp.post("")
@api_key_auth
@inject.autoparams()
def add(users: UserRepository) -> Response:
Expand All @@ -74,7 +74,7 @@ def add(users: UserRepository) -> Response:
return Response(status=201)


@bp.route("", methods=["DELETE"])
@bp.delete("")
@api_key_auth
@inject.autoparams()
def clear(users: UserRepository) -> Response:
Expand Down
20 changes: 10 additions & 10 deletions tests/e2e/oidc_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,29 @@ def create_app(test_config: dict[str, Any] | None = None) -> OidcServerApp:
authorization_server = app.create_authorization_server(key)
require_oauth = app.create_resource_protector()

@app.route("/users", methods=["POST"])
@app.post("/users")
def add_user() -> Response:
user = StubUser(**request.get_json())
app.add_user(user)
return Response(status=201)

@app.route("/users", methods=["DELETE"])
@app.delete("/users")
def clear_users() -> Response:
app.clear_users()
return Response(status=204)

@app.route("/clients", methods=["POST"])
@app.post("/clients")
def add_client() -> Response:
client = StubClient(**request.get_json())
app.add_client(client)
return Response(status=201)

@app.route("/clients", methods=["DELETE"])
@app.delete("/clients")
def clear_clients() -> Response:
app.clear_clients()
return Response(status=204)

@app.route("/.well-known/openid-configuration")
@app.get("/.well-known/openid-configuration")
def openid_configuration() -> Response:
return jsonify(
{
Expand All @@ -137,7 +137,7 @@ def openid_configuration() -> Response:
}
)

@app.route("/authorize")
@app.get("/authorize")
def authorize() -> Response:
authorized_user = app.authorized_user()

Expand All @@ -147,22 +147,22 @@ def authorize() -> Response:
response: Response = authorization_server.create_authorization_response(grant_user=authorized_user)
return response

@app.route("/token", methods=["POST"])
@app.post("/token")
def token() -> Response:
response: Response = authorization_server.create_token_response()
return response

@app.route("/userinfo")
@app.get("/userinfo")
@require_oauth("openid email")
def userinfo() -> Response:
user = app.current_user()
return jsonify(StubUserInfo(user))

@app.route("/jwks_uri")
@app.get("/jwks_uri")
def jwks() -> Response:
return jsonify(KeySet([key]).as_dict())

@app.route("/logout")
@app.get("/logout")
def logout() -> BaseResponse:
id_token_hint = request.args.get("id_token_hint")
post_logout_redirect_uri = request.args.get("post_logout_redirect_uri")
Expand Down

0 comments on commit a06ae8f

Please sign in to comment.