mirror of
https://github.com/p-stream/p-stream.git
synced 2026-03-11 17:55:33 +00:00
update redirect uri logic
This commit is contained in:
parent
1bb1e2f9d9
commit
f0dde1e78f
3 changed files with 15 additions and 21 deletions
|
|
@ -19,11 +19,7 @@ export function TraktAuthHandler() {
|
||||||
setStatus("syncing");
|
setStatus("syncing");
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
const redirectUri = `${window.location.origin}${window.location.pathname}`;
|
const success = await traktService.exchangeCodeForToken(code);
|
||||||
const success = await traktService.exchangeCodeForToken(
|
|
||||||
code,
|
|
||||||
redirectUri,
|
|
||||||
);
|
|
||||||
if (success) {
|
if (success) {
|
||||||
const newParams = new URLSearchParams(searchParams);
|
const newParams = new URLSearchParams(searchParams);
|
||||||
newParams.delete("code");
|
newParams.delete("code");
|
||||||
|
|
|
||||||
|
|
@ -780,18 +780,20 @@ export function TraktEdit() {
|
||||||
const config = conf();
|
const config = conf();
|
||||||
|
|
||||||
const connect = () => {
|
const connect = () => {
|
||||||
const redirectUri =
|
|
||||||
config.TRAKT_REDIRECT_URI ??
|
|
||||||
`${window.location.origin}${window.location.pathname}`;
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
response_type: "code",
|
response_type: "code",
|
||||||
client_id: config.TRAKT_CLIENT_ID ?? "",
|
client_id: config.TRAKT_CLIENT_ID ?? "",
|
||||||
redirect_uri: redirectUri,
|
redirect_uri: config.TRAKT_REDIRECT_URI ?? "",
|
||||||
});
|
});
|
||||||
window.location.href = `https://trakt.tv/oauth/authorize?${params.toString()}`;
|
window.location.href = `https://trakt.tv/oauth/authorize?${params.toString()}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!config.TRAKT_CLIENT_ID || !config.TRAKT_CLIENT_SECRET) return null;
|
if (
|
||||||
|
!config.TRAKT_CLIENT_ID ||
|
||||||
|
!config.TRAKT_CLIENT_SECRET ||
|
||||||
|
!config.TRAKT_REDIRECT_URI
|
||||||
|
)
|
||||||
|
return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingsCard>
|
<SettingsCard>
|
||||||
|
|
|
||||||
|
|
@ -45,19 +45,15 @@ export class TraktService {
|
||||||
}&redirect_uri=${encodeURIComponent(config.TRAKT_REDIRECT_URI)}`;
|
}&redirect_uri=${encodeURIComponent(config.TRAKT_REDIRECT_URI)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async exchangeCodeForToken(
|
public async exchangeCodeForToken(code: string): Promise<boolean> {
|
||||||
code: string,
|
|
||||||
redirectUri?: string,
|
|
||||||
): Promise<boolean> {
|
|
||||||
const config = conf();
|
const config = conf();
|
||||||
if (!config.TRAKT_CLIENT_ID || !config.TRAKT_CLIENT_SECRET)
|
if (
|
||||||
|
!config.TRAKT_CLIENT_ID ||
|
||||||
|
!config.TRAKT_CLIENT_SECRET ||
|
||||||
|
!config.TRAKT_REDIRECT_URI
|
||||||
|
)
|
||||||
throw new Error("Missing Trakt config");
|
throw new Error("Missing Trakt config");
|
||||||
|
|
||||||
const resolvedRedirectUri =
|
|
||||||
redirectUri ?? config.TRAKT_REDIRECT_URI ?? undefined;
|
|
||||||
if (!resolvedRedirectUri)
|
|
||||||
throw new Error("Missing redirect_uri for token exchange");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await ofetch(`${TRAKT_API_URL}/oauth/token`, {
|
const data = await ofetch(`${TRAKT_API_URL}/oauth/token`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
@ -66,7 +62,7 @@ export class TraktService {
|
||||||
code,
|
code,
|
||||||
client_id: config.TRAKT_CLIENT_ID,
|
client_id: config.TRAKT_CLIENT_ID,
|
||||||
client_secret: config.TRAKT_CLIENT_SECRET,
|
client_secret: config.TRAKT_CLIENT_SECRET,
|
||||||
redirect_uri: resolvedRedirectUri,
|
redirect_uri: config.TRAKT_REDIRECT_URI,
|
||||||
grant_type: "authorization_code",
|
grant_type: "authorization_code",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue