tangled
alpha
login
or
join now
dunkirk.sh
/
pstream-ng
1
fork
atom
pstream is dead; long live pstream
taciturnaxolotl.github.io/pstream-ng/
1
fork
atom
overview
issues
pulls
pipelines
update redirect uri logic
Pas
1 month ago
f0dde1e7
1bb1e2f9
+15
-21
3 changed files
expand all
collapse all
unified
split
src
components
TraktAuthHandler.tsx
pages
parts
settings
ConnectionsPart.tsx
utils
trakt.ts
+1
-5
src/components/TraktAuthHandler.tsx
reviewed
···
19
19
setStatus("syncing");
20
20
setError(null);
21
21
try {
22
22
-
const redirectUri = `${window.location.origin}${window.location.pathname}`;
23
23
-
const success = await traktService.exchangeCodeForToken(
24
24
-
code,
25
25
-
redirectUri,
26
26
-
);
22
22
+
const success = await traktService.exchangeCodeForToken(code);
27
23
if (success) {
28
24
const newParams = new URLSearchParams(searchParams);
29
25
newParams.delete("code");
+7
-5
src/pages/parts/settings/ConnectionsPart.tsx
reviewed
···
780
780
const config = conf();
781
781
782
782
const connect = () => {
783
783
-
const redirectUri =
784
784
-
config.TRAKT_REDIRECT_URI ??
785
785
-
`${window.location.origin}${window.location.pathname}`;
786
783
const params = new URLSearchParams({
787
784
response_type: "code",
788
785
client_id: config.TRAKT_CLIENT_ID ?? "",
789
789
-
redirect_uri: redirectUri,
786
786
+
redirect_uri: config.TRAKT_REDIRECT_URI ?? "",
790
787
});
791
788
window.location.href = `https://trakt.tv/oauth/authorize?${params.toString()}`;
792
789
};
793
790
794
794
-
if (!config.TRAKT_CLIENT_ID || !config.TRAKT_CLIENT_SECRET) return null;
791
791
+
if (
792
792
+
!config.TRAKT_CLIENT_ID ||
793
793
+
!config.TRAKT_CLIENT_SECRET ||
794
794
+
!config.TRAKT_REDIRECT_URI
795
795
+
)
796
796
+
return null;
795
797
796
798
return (
797
799
<SettingsCard>
+7
-11
src/utils/trakt.ts
reviewed
···
45
45
}&redirect_uri=${encodeURIComponent(config.TRAKT_REDIRECT_URI)}`;
46
46
}
47
47
48
48
-
public async exchangeCodeForToken(
49
49
-
code: string,
50
50
-
redirectUri?: string,
51
51
-
): Promise<boolean> {
48
48
+
public async exchangeCodeForToken(code: string): Promise<boolean> {
52
49
const config = conf();
53
53
-
if (!config.TRAKT_CLIENT_ID || !config.TRAKT_CLIENT_SECRET)
50
50
+
if (
51
51
+
!config.TRAKT_CLIENT_ID ||
52
52
+
!config.TRAKT_CLIENT_SECRET ||
53
53
+
!config.TRAKT_REDIRECT_URI
54
54
+
)
54
55
throw new Error("Missing Trakt config");
55
55
-
56
56
-
const resolvedRedirectUri =
57
57
-
redirectUri ?? config.TRAKT_REDIRECT_URI ?? undefined;
58
58
-
if (!resolvedRedirectUri)
59
59
-
throw new Error("Missing redirect_uri for token exchange");
60
56
61
57
try {
62
58
const data = await ofetch(`${TRAKT_API_URL}/oauth/token`, {
···
66
62
code,
67
63
client_id: config.TRAKT_CLIENT_ID,
68
64
client_secret: config.TRAKT_CLIENT_SECRET,
69
69
-
redirect_uri: resolvedRedirectUri,
65
65
+
redirect_uri: config.TRAKT_REDIRECT_URI,
70
66
grant_type: "authorization_code",
71
67
},
72
68
});