core: add automatic launch_url detection based on provider
This commit is contained in:
@ -6,6 +6,7 @@ import time
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from hashlib import sha256
|
||||
from typing import Any, Dict, List, Optional, Type
|
||||
from urllib.parse import urlparse
|
||||
from uuid import uuid4
|
||||
|
||||
from django.conf import settings
|
||||
@ -230,6 +231,16 @@ class OAuth2Provider(Provider):
|
||||
except Provider.application.RelatedObjectDoesNotExist:
|
||||
return None
|
||||
|
||||
@property
|
||||
def launch_url(self) -> Optional[str]:
|
||||
"""Guess launch_url based on first redirect_uri"""
|
||||
if not self.redirect_uris:
|
||||
return None
|
||||
main_url = self.redirect_uris[0]
|
||||
launch_url = urlparse(main_url)
|
||||
launch_url.path = ""
|
||||
return launch_url.geturl()
|
||||
|
||||
def form(self) -> Type[ModelForm]:
|
||||
from passbook.providers.oauth2.forms import OAuth2ProviderForm
|
||||
|
||||
|
Reference in New Issue
Block a user