HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/aigenerator/venv/lib/python3.12/site-packages/social_core/backends/grafana.py
from social_core.backends.oauth import BaseOAuth2


class GrafanaOAuth2(BaseOAuth2):
    """Grafana OAuth authentication backend"""

    name = "grafana"
    AUTHORIZATION_URL = "https://grafana.com/oauth2/authorize"
    ACCESS_TOKEN_URL = "https://grafana.com/api/oauth2/token"
    ACCESS_TOKEN_METHOD = "POST"
    DEFAULT_SCOPE = ["profile", "email"]
    SCOPE_SEPARATOR = ","
    USER_DETAILS_URL = "https://grafana.com/api/oauth2/user"

    def get_user_details(self, response):
        """Return user details from Grafana account"""
        return {
            "username": response.get("login"),
            "email": response.get("email") or "",
            "first_name": response.get("name"),
            "last_name": "-",
        }

    def user_data(self, access_token, *args, **kwargs):
        """Loads user data from service"""
        return self.get_json(
            self.USER_DETAILS_URL,
            **{"headers": {"Authorization": f"Bearer {access_token}"}},
        )