Skip to content

Commit

Permalink
Merge pull request #49 from Infomaniak/get_configure_view
Browse files Browse the repository at this point in the history
fix: strongly type get_configure_view
  • Loading branch information
dlouzan authored Sep 12, 2024
2 parents d880ca4 + 934ec42 commit df07034
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 16 deletions.
17 changes: 14 additions & 3 deletions oidc/provider.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
from __future__ import annotations

from collections.abc import Callable

from django.http import HttpRequest

import time

import requests
from sentry.auth.provider import MigratingIdentityId
from sentry.auth.providers.oauth2 import OAuth2Callback, OAuth2Login, OAuth2Provider
from sentry.auth.services.auth.model import RpcAuthProvider
from sentry.organizations.services.organization.model import RpcOrganization
from sentry.plugins.base.response import DeferredResponse

from .constants import (
AUTHORIZATION_ENDPOINT,
Expand All @@ -14,7 +23,7 @@
TOKEN_ENDPOINT,
USERINFO_ENDPOINT,
)
from .views import FetchUser, OIDCConfigureView
from .views import FetchUser, oidc_configure_view


class OIDCLogin(OAuth2Login):
Expand Down Expand Up @@ -63,8 +72,10 @@ def get_client_id(self):
def get_client_secret(self):
return CLIENT_SECRET

def get_configure_view(self):
return OIDCConfigureView.as_view()
def get_configure_view(
self,
) -> Callable[[HttpRequest, RpcOrganization, RpcAuthProvider], DeferredResponse]:
return oidc_configure_view

def get_auth_pipeline(self):
return [
Expand Down
36 changes: 23 additions & 13 deletions oidc/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from __future__ import annotations

import logging

from sentry.auth.view import AuthView, ConfigureView
from django.http import HttpRequest
from rest_framework.response import Response

from sentry.auth.services.auth.model import RpcAuthProvider
from sentry.auth.view import AuthView
from sentry.utils import json
from sentry.organizations.services.organization.model import RpcOrganization
from sentry.plugins.base.response import DeferredResponse
from sentry.utils.signing import urlsafe_b64decode

from .constants import ERR_INVALID_RESPONSE, ISSUER
Expand All @@ -15,7 +23,7 @@ def __init__(self, domains, version, *args, **kwargs):
self.version = version
super().__init__(*args, **kwargs)

def dispatch(self, request, helper):
def dispatch(self, request: HttpRequest, helper) -> Response: # type: ignore
data = helper.fetch_state("data")

try:
Expand Down Expand Up @@ -52,17 +60,19 @@ def dispatch(self, request, helper):
return helper.next_step()


class OIDCConfigureView(ConfigureView):
def dispatch(self, request, organization, auth_provider):
config = auth_provider.config
if config.get("domain"):
domains = [config["domain"]]
else:
domains = config.get("domains")
return self.render(
"oidc/configure.html",
{"provider_name": ISSUER or "", "domains": domains or []},
)
def oidc_configure_view(
request: HttpRequest, organization: RpcOrganization, auth_provider: RpcAuthProvider
) -> DeferredResponse:
config = auth_provider.config
if config.get("domain"):
domains: list[str] | None
domains = [config["domain"]]
else:
domains = config.get("domains")
return DeferredResponse(
"oidc/configure.html",
{"provider_name": ISSUER or "", "domains": domains or []}
)


def extract_domain(email):
Expand Down

0 comments on commit df07034

Please sign in to comment.