diff --git a/.env.example b/.env.example index a1089c44..cd67a291 100644 --- a/.env.example +++ b/.env.example @@ -41,7 +41,7 @@ THEMOVIEDB_APIKEY= # The url you can use to reach your kyoo instance. This is used during oidc to redirect users to your instance. PUBLIC_URL=http://localhost:5000 -# Use a builtin oidc service (google, discord, or simkl): +# Use a builtin oidc service (google, discord, trakt, or simkl): # When you create a client_id, secret combo you may be asked for a redirect url. You need to specify https://YOUR-PUBLIC-URL/api/auth/logged/YOUR-SERVICE-NAME OIDC_DISCORD_CLIENTID= OIDC_DISCORD_SECRET= diff --git a/back/src/Kyoo.Authentication/Models/DTO/JwtProfile.cs b/back/src/Kyoo.Authentication/Models/DTO/JwtProfile.cs index 85272f8b..c1de4fbb 100644 --- a/back/src/Kyoo.Authentication/Models/DTO/JwtProfile.cs +++ b/back/src/Kyoo.Authentication/Models/DTO/JwtProfile.cs @@ -63,8 +63,12 @@ public class JwtProfile { if (value is null) return; + // trakt store their name there (they also store name but that's not the same). + Username ??= value["username"]?.ToString(); // simkl store their name there. Username ??= value["name"]?.ToString(); + + Sub ??= value["ids"]?["uuid"]?.ToString(); } } diff --git a/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs b/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs index cd41c0bb..90b8cb67 100644 --- a/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs +++ b/back/src/Kyoo.Authentication/Models/Options/PermissionOption.cs @@ -148,5 +148,19 @@ public class OidcProvider GetExtraHeaders = (OidcProvider self) => new() { ["simkl-api-key"] = self.ClientId }, }, + ["trakt"] = new("trakt") + { + DisplayName = "Trakt", + LogoUrl = "https://logo.clearbit.com/trakt.tv", + AuthorizationUrl = "https://api.trakt.tv/oauth/authorize", + TokenUrl = "https://api.trakt.tv/oauth/token", + ProfileUrl = "https://api.trakt.tv/users/settings", + // does not seems to have scopes + Scope = null, + TokenUseJsonBody = true, + GetProfileUrl = (profile) => $"https://trakt.tv/users/{profile.Username}", + GetExtraHeaders = (OidcProvider self) => + new() { ["trakt-api-key"] = self.ClientId, ["trakt-api-version"] = "2", }, + }, }; }