Skip to content

Commit

Permalink
fix: switch to pkce-challenge package to support browser
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Sep 27, 2023
1 parent a75a901 commit 685fa9a
Show file tree
Hide file tree
Showing 3 changed files with 6,181 additions and 6,061 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@
"dependencies": {
"@react-native-async-storage/async-storage": "^1.19.3",
"jwt-decode": "^3.1.2",
"react-native-pkce-challenge": "^5.2.0"
"pkce-challenge": "3.1.0"
}
}
6 changes: 3 additions & 3 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import AsyncStorage from '@react-native-async-storage/async-storage';
import jwtDecode from 'jwt-decode';
import pkceChallenge from 'react-native-pkce-challenge'
import pkceChallenge from 'pkce-challenge';

export interface SdkConfig {
serverUrl: string, // your Casdoor server URL, e.g., 'https://door.casdoor.com' for the official demo site
Expand Down Expand Up @@ -82,7 +82,7 @@ class Sdk {
const redirectUri = this.config.redirectPath && this.config.redirectPath.includes('://') ? this.config.redirectPath : `${window.location.origin}${this.config.redirectPath}`;
const scope = 'read';
const state = await this.getOrSaveState();
return `${this.config.serverUrl.trim()}/login/oauth/authorize?client_id=${this.config.clientId}&response_type=code&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${scope}&state=${state}&code_challenge=${this.pkce.codeChallenge}&code_challenge_method=S256`;
return `${this.config.serverUrl.trim()}/login/oauth/authorize?client_id=${this.config.clientId}&response_type=code&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${scope}&state=${state}&code_challenge=${this.pkce.code_challenge}&code_challenge_method=S256`;
}

public getUserProfileUrl(userName: string, account: Account): string {
Expand Down Expand Up @@ -126,7 +126,7 @@ class Sdk {
'Content-Type': 'application/x-www-form-urlencoded',
},
// @ts-ignore
body: `client_id=${this.config.clientId}&grant_type=authorization_code&code=${code}&redirect_uri=${encodeURIComponent(this.config.redirectPath)}&code_verifier=${this.pkce.codeVerifier}`,
body: `client_id=${this.config.clientId}&grant_type=authorization_code&code=${code}&redirect_uri=${encodeURIComponent(this.config.redirectPath)}&code_verifier=${this.pkce.code_verifier}`,
credentials: 'include',
});
if (response.ok) {
Expand Down
Loading

0 comments on commit 685fa9a

Please sign in to comment.