mirror of
https://github.com/tapframe/NuvioStreaming.git
synced 2026-04-27 11:23:02 +00:00
ref: Simkl authentication to use PKCE and update exchangeCodeForToken method
This commit is contained in:
parent
5a8fa30787
commit
37ad5647f8
2 changed files with 13 additions and 9 deletions
|
|
@ -27,7 +27,6 @@ const ANDROID_STATUSBAR_HEIGHT = StatusBar.currentHeight || 0;
|
||||||
|
|
||||||
// Simkl configuration
|
// Simkl configuration
|
||||||
const SIMKL_CLIENT_ID = process.env.EXPO_PUBLIC_SIMKL_CLIENT_ID as string;
|
const SIMKL_CLIENT_ID = process.env.EXPO_PUBLIC_SIMKL_CLIENT_ID as string;
|
||||||
const SIMKL_REDIRECT_URI = process.env.EXPO_PUBLIC_SIMKL_REDIRECT_URI || 'nuvio://auth/simkl';
|
|
||||||
|
|
||||||
const discovery = {
|
const discovery = {
|
||||||
authorizationEndpoint: 'https://simkl.com/oauth/authorize',
|
authorizationEndpoint: 'https://simkl.com/oauth/authorize',
|
||||||
|
|
@ -76,9 +75,10 @@ const SimklSettingsScreen: React.FC = () => {
|
||||||
{
|
{
|
||||||
clientId: SIMKL_CLIENT_ID,
|
clientId: SIMKL_CLIENT_ID,
|
||||||
scopes: [], // Simkl doesn't strictly use scopes for basic access
|
scopes: [], // Simkl doesn't strictly use scopes for basic access
|
||||||
redirectUri: SIMKL_REDIRECT_URI, // Must match what is set in Simkl Dashboard
|
redirectUri: redirectUri,
|
||||||
responseType: ResponseType.Code,
|
responseType: ResponseType.Code,
|
||||||
// codeChallengeMethod: CodeChallengeMethod.S256, // Simkl might not verify PKCE, but standard compliant
|
usePKCE: true,
|
||||||
|
codeChallengeMethod: CodeChallengeMethod.S256,
|
||||||
},
|
},
|
||||||
discovery
|
discovery
|
||||||
);
|
);
|
||||||
|
|
@ -90,12 +90,12 @@ const SimklSettingsScreen: React.FC = () => {
|
||||||
// Handle the response from the auth request
|
// Handle the response from the auth request
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (response) {
|
if (response) {
|
||||||
if (response.type === 'success') {
|
if (response.type === 'success' && request?.codeVerifier) {
|
||||||
const { code } = response.params;
|
const { code } = response.params;
|
||||||
setIsExchangingCode(true);
|
setIsExchangingCode(true);
|
||||||
logger.log('[SimklSettingsScreen] Auth code received, exchanging...');
|
logger.log('[SimklSettingsScreen] Auth code received, exchanging...');
|
||||||
|
|
||||||
simklService.exchangeCodeForToken(code)
|
simklService.exchangeCodeForToken(code, request.codeVerifier)
|
||||||
.then(success => {
|
.then(success => {
|
||||||
if (success) {
|
if (success) {
|
||||||
refreshAuthStatus();
|
refreshAuthStatus();
|
||||||
|
|
@ -109,11 +109,14 @@ const SimklSettingsScreen: React.FC = () => {
|
||||||
openAlert(t('common.error'), t('simkl.auth_error_generic'));
|
openAlert(t('common.error'), t('simkl.auth_error_generic'));
|
||||||
})
|
})
|
||||||
.finally(() => setIsExchangingCode(false));
|
.finally(() => setIsExchangingCode(false));
|
||||||
|
} else if (response.type === 'success') {
|
||||||
|
logger.error('[SimklSettingsScreen] Missing PKCE code verifier on successful auth response');
|
||||||
|
openAlert(t('common.error'), t('simkl.auth_error_msg'));
|
||||||
} else if (response.type === 'error') {
|
} else if (response.type === 'error') {
|
||||||
openAlert(t('simkl.auth_error_title'), t('simkl.auth_error_generic') + ' ' + (response.error?.message || t('common.unknown')));
|
openAlert(t('simkl.auth_error_title'), t('simkl.auth_error_generic') + ' ' + (response.error?.message || t('common.unknown')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [response, refreshAuthStatus]);
|
}, [response, refreshAuthStatus, request?.codeVerifier, t]);
|
||||||
|
|
||||||
const handleSignIn = () => {
|
const handleSignIn = () => {
|
||||||
if (!SIMKL_CLIENT_ID) {
|
if (!SIMKL_CLIENT_ID) {
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ export class SimklService {
|
||||||
* Exchange code for access token
|
* Exchange code for access token
|
||||||
* Simkl tokens do not expire
|
* Simkl tokens do not expire
|
||||||
*/
|
*/
|
||||||
public async exchangeCodeForToken(code: string): Promise<boolean> {
|
public async exchangeCodeForToken(code: string, codeVerifier: string): Promise<boolean> {
|
||||||
await this.ensureInitialized();
|
await this.ensureInitialized();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -315,7 +315,8 @@ export class SimklService {
|
||||||
client_id: SIMKL_CLIENT_ID,
|
client_id: SIMKL_CLIENT_ID,
|
||||||
client_secret: SIMKL_CLIENT_SECRET,
|
client_secret: SIMKL_CLIENT_SECRET,
|
||||||
redirect_uri: SIMKL_REDIRECT_URI,
|
redirect_uri: SIMKL_REDIRECT_URI,
|
||||||
grant_type: 'authorization_code'
|
grant_type: 'authorization_code',
|
||||||
|
code_verifier: codeVerifier
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue