All Auth and Swagger

81 views Asked by At

I'm trying to use Django All Auth and DRF YASG (Yet another swagger generator) to use Googles OAuth2.

I was able to use Django Session Authentication to pop open the google auth portal and successfully log in the user, however I now need to use this functionality from an outside source, prompting me to need to use the swagger oath.

This is my current setup.

# Swagger

SWAGGER_SETTINGS = {
    "DEFAULT_INFO": "django_project.urls.app_info",
    "USE_SESSION_AUTH": False,
    "SECURITY_DEFINITIONS": {
        "Your App API - Swagger": {
            "type": "oauth2",
            "authorizationUrl": "accounts/google/login",
            "tokenUrl": "accounts/google/login/callback",
            "flow": "accessCode",
        }
    },
    "OAUTH2_REDIRECT_URL": "accounts/google/login",
    "OAUTH2_CONFIG": {
        "clientId": OAUTH_CLIENT,
        "clientSecret": OAUTH_SECRET,
        "appName": "PushApp",
    },
}

# Oauth2

LOGIN_REDIRECT_URL = "/"
LOGOUT_REDIRECT_URL = "/"

ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True

SOCIALACCOUNT_LOGIN_ON_GET = True
ACCOUNT_LOGOUT_ON_GET = True

AUTHENTICATION_BACKENDS = [
    "django.contrib.auth.backends.ModelBackend",
    "allauth.account.auth_backends.AuthenticationBackend",
]

SOCIALACCOUNT_PROVIDERS = {
    "google": {
        "EMAIL_AUTHENTICATION": True,
        "APP": {
            "client_id": OAUTH_CLIENT,
            "secret": OAUTH_SECRET,
            "key": "",
        },
        "SCOPE": [
            "profile",
            "email",
        ],
        "AUTH_PARAMS": {
            "access_type": "online",
        },
    }
}

This setup successfully opens the google login portal, however, when it redirects back to the swagger page, I am not logged in.

The problem must be in my redirect urls, being authorizationUrl, tokenUrl, or OAUTH2_REDIRECT_URL. However, I'm not sure what to set them to.

0

There are 0 answers