Skip to content

Connect sso plex by authentik #863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
morganorix opened this issue Aug 24, 2024 · 0 comments
Open

Connect sso plex by authentik #863

morganorix opened this issue Aug 24, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@morganorix
Copy link

morganorix commented Aug 24, 2024

Is your feature request related to a problem? Please describe.
There is a strange behavior when I generate a cookie via authentik. I end up on the login page. All I have to do is click on login without filling in any fields and it skips the login page.

Describe the solution you'd like
One solution is to set up an oauth system or a petio refresh test if a cross-site cookie is detected. It'll be cleaner

This is a scope's authentik for petio (I was inspired by your source codes) :

from authentik.sources.plex.models import PlexSourceConnection
import json
from datetime import datetime, timedelta

connection = PlexSourceConnection.objects.filter(user=request.user).first()
if not connection:
    return {}

petio_url = "http://192.168.1.190:7777/api/login/plex_login"

def get_client_ip(request):
    x_forwarded_for = request.http_request.META['HTTP_X_FORWARDED_FOR']
    if x_forwarded_for:
        ip = x_forwarded_for.split(',')[0]
    else:
        ip = http_request.META['REMOTE_ADDR']
    return ip

headers = {
    "Accept": "application/json",
    "Content-Type": "application/x-www-form-urlencoded",
    "X-Forwarded-For": get_client_ip(request)
}

data = {
    "user": {
			"username": "",
			"password": "",
			"type": 1,
		},
		'authToken': False,
		'token': connection.plex_token
}

response = requests.post(petio_url, headers=headers, data=data, verify=False, timeout=60, allow_redirects=True)

user = response.json().get('user')

if (response.status_code != 200):
    return {}

token = response.json().get('token')

return {
    "ak_proxy": {
        "user_attributes": {
            "additionalHeaders": {
                "Cookie": f"petio_jwt={token}; expires={(datetime.now() + timedelta(days=1)).strftime('%a, %d %b %Y %H:%M:%S')} GMT;"
            }
        }
    }
}

When I click to go to petio from my authentik interface, authentik generates the cookie and adds it to the header

@morganorix morganorix added the enhancement New feature or request label Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant