Scope Mapping #1
Replies: 3 comments 2 replies
-
I looked at how it was made in Organizr (in this file), since it was able to login to those services. To be honest, sometimes it doesn't work much (Tautulli can be a bit bothering and Plex requires to accept the domain at least once, if you're using a subdomain). The main thing those functions do is to generate the login cookie based on the Plex token of the user, if they have linked their account to Plex in Authentik, by doing the request on behalf of the user to the service. The request URIs are internal and use the Docker host:port since the containers are in the same network. I had to use two different middlewares in Traefik to be able to transmit the generated cookies. The services using Plex Auth use their separated middleware, while the other services have their own. The only addition in the I think the following scope mappings may be further improved, like with cookie validity checks (depending on the cookie duration for instance), and I didn't check if some additional stuff were added to the SSO functions in Organizr to further improve that, but it works in most cases. Overseerrfrom authentik.sources.plex.models import PlexSourceConnection
from datetime import datetime, timedelta
import json
connection = PlexSourceConnection.objects.filter(user=request.user).first()
if not connection:
return {}
overseerr_url = "http://overseerr:5055/api/v1/auth/plex"
headers = {
"Content-Type": "application/json",
"X-Forwarded-For": request.http_request.META['REMOTE_ADDR']
}
data = {
"email": "",
"password": "",
"authToken": connection.plex_token
}
response = requests.post(overseerr_url, headers=headers, data=json.dumps(data), verify=False, timeout=60, allow_redirects=True)
if (response.status_code != 200):
return {}
token = response.cookies['connect.sid']
return {
"ak_proxy": {
"user_attributes": {
"additionalHeaders": {
"Cookie": f"connect.sid={token}; expires={(datetime.now() + timedelta(days=1)).strftime('%a, %d %b %Y %H:%M:%S')} GMT; Path=/"
}
}
}
} Tautullifrom 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 {}
tautulli_url = "http://tautulli:8181/auth/signin"
headers = {
"Accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": request.http_request.META['HTTP_USER_AGENT'],
"X-Forwarded-For": request.http_request.META['REMOTE_ADDR']
}
data = {
"username": "",
"password": "",
"token": connection.plex_token
}
response = requests.post(tautulli_url, headers=headers, data=data, verify=False, timeout=60, allow_redirects=True)
if (response.status_code != 200):
return {}
uuid = response.json().get('uuid')
token = response.json().get('token')
return {
"ak_proxy": {
"user_attributes": {
"additionalHeaders": {
"Cookie": f"tautulli_token_{uuid}={token}; expires={(datetime.now() + timedelta(days=1)).strftime('%a, %d %b %Y %H:%M:%S')} GMT; Path=/"
}
}
}
} Plexfrom authentik.sources.plex.models import PlexSourceConnection
from datetime import datetime, timedelta
connection = PlexSourceConnection.objects.filter(user=request.user).first()
if not connection:
return {}
return {
"ak_proxy": {
"user_attributes": {
"additionalHeaders": {
"Cookie": f"mpt={connection.plex_token}; expires={(datetime.now() + timedelta(days=1)).strftime('%a, %d %b %Y %H:%M:%S')} GMT; path=/; SameSite=None; Secure"
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Hello, thx for the good job. Traceback (most recent call last): Are you a specific conf nginx ? |
Beta Was this translation helpful? Give feedback.
-
I've adapt the code for petio :
|
Beta Was this translation helpful? Give feedback.
-
This is an awesome repo and has greatly helped me with understanding setting up Traefik with Authentik. I was curious whether you could post the scope mapping scripts that you are using for the various services like Overseerr and Tautulli. I had Authentik working with Overseerr before switching to Traefik from Nginx Proxy Manager, but have never had much luck with Tautulli.
Beta Was this translation helpful? Give feedback.
All reactions