Skip to content

Commit

Permalink
Merge pull request #35 from kinde-oss/refactor/remove-old-dependancies
Browse files Browse the repository at this point in the history
Refactor: removed dependancies
  • Loading branch information
DanielRivers authored Jun 26, 2024
2 parents fa60bf1 + 9a7d4af commit 206f55c
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 119 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### 1.3.0

- Change type login and register [`#29`](https://github.com/kinde-oss/kinde-react-native-sdk-0-7x/pull/29)
- feature/force-token-refresh [`#32`](https://github.com/kinde-oss/kinde-react-native-sdk-0-7x/pull/32)
188 changes: 108 additions & 80 deletions __tests__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,20 +287,22 @@ describe('KindeSDK', () => {
test('[RNStorage] Open authenticate endpoint', async () => {
InAppBrowser.isAvailable = jest.fn().mockReturnValue(true);
await globalClient.login();
const URLParsed = Url(`${configuration.issuer}/oauth2/auth`, true);
URLParsed.query['client_id'] = configuration.clientId;
URLParsed.query['redirect_uri'] = configuration.redirectUri;
URLParsed.query['client_secret'] = configuration.clientSecret;
URLParsed.query['scope'] = configuration.scope;
URLParsed.query['grant_type'] = 'authorization_code';
URLParsed.query['response_type'] = 'code';
URLParsed.query['start_page'] = 'login';
URLParsed.query['state'] = configuration.fakeState;
URLParsed.query['code_challenge'] = configuration.fakeCodeChallenge;
URLParsed.query['code_challenge_method'] = 'S256';

const urlParmams = new URLSearchParams({
client_id: configuration.clientId,
redirect_uri: configuration.redirectUri,
client_secret: configuration.clientSecret || '',
scope: configuration.scope,
grant_type: 'authorization_code',
response_type: 'code',
start_page: 'login',
state: configuration.fakeState,
code_challenge: configuration.fakeCodeChallenge,
code_challenge_method: 'S256'
}).toString();

expect(InAppBrowser.openAuth).toHaveBeenCalledWith(
URLParsed.toString(),
`${configuration.issuer}/oauth2/auth?${urlParmams}`,
globalClient.redirectUri,
{
enableDefaultShare: false,
Expand All @@ -314,19 +316,36 @@ describe('KindeSDK', () => {
test('[RNStorage] Open registration endpoint', async () => {
InAppBrowser.isAvailable = jest.fn().mockReturnValue(true);
await globalClient.register();
const URLParsed = Url(configuration.authorizationEndpoint, true);
URLParsed.query['client_id'] = configuration.clientId;
URLParsed.query['redirect_uri'] = configuration.redirectUri;
URLParsed.query['client_secret'] = configuration.clientSecret;
URLParsed.query['scope'] = configuration.scope;
URLParsed.query['grant_type'] = 'authorization_code';
URLParsed.query['response_type'] = 'code';
URLParsed.query['start_page'] = 'registration';
URLParsed.query['state'] = configuration.fakeState;
URLParsed.query['code_challenge'] = configuration.fakeCodeChallenge;
URLParsed.query['code_challenge_method'] = 'S256';

console.log(
new URLSearchParams({
client_id: configuration.clientId || '',
redirect_uri: configuration.redirectUri || '',
client_secret: configuration.clientSecret || '',
scope: configuration.scope || '',
grant_type: 'authorization_code',
response_type: 'code',
start_page: 'registration',
state: configuration.fakeState || '',
code_challenge: configuration.fakeCodeChallenge || '',
code_challenge_method: 'S256'
}).toString()
);
expect(InAppBrowser.openAuth).toHaveBeenCalledWith(
URLParsed.toString(),
configuration.authorizationEndpoint +
'?' +
new URLSearchParams({
client_id: configuration.clientId || '',
redirect_uri: configuration.redirectUri || '',
client_secret: configuration.clientSecret || '',
scope: configuration.scope || '',
grant_type: 'authorization_code',
response_type: 'code',
start_page: 'registration',
state: configuration.fakeState || '',
code_challenge: configuration.fakeCodeChallenge || '',
code_challenge_method: 'S256'
}).toString(),
globalClient.redirectUri,
{
enableDefaultShare: false,
Expand All @@ -340,10 +359,10 @@ describe('KindeSDK', () => {
test('[RNStorage] Logout', async () => {
InAppBrowser.isAvailable = jest.fn().mockReturnValue(true);
await globalClient.logout();
const URLParsed = Url(configuration.logoutEndpoint, true);
URLParsed.query['redirect'] = configuration.logoutRedirectUri;
expect(InAppBrowser.openAuth).toHaveBeenCalledWith(
URLParsed.toString(),
`${configuration.logoutEndpoint}?${new URLSearchParams({
redirect: configuration.logoutRedirectUri
}).toString()}`,
globalClient.redirectUri,
{
enableDefaultShare: false,
Expand Down Expand Up @@ -390,20 +409,23 @@ describe('KindeSDK', () => {
test('[RNStorage] Create Organization', async () => {
InAppBrowser.isAvailable = jest.fn().mockReturnValue(true);
await globalClient.createOrg();
const URLParsed = Url(configuration.authorizationEndpoint, true);
URLParsed.query['client_id'] = configuration.clientId;
URLParsed.query['redirect_uri'] = configuration.redirectUri;
URLParsed.query['client_secret'] = configuration.clientSecret;
URLParsed.query['scope'] = configuration.scope;
URLParsed.query['grant_type'] = 'authorization_code';
URLParsed.query['response_type'] = 'code';
URLParsed.query['start_page'] = 'registration';
URLParsed.query['state'] = configuration.fakeState;
URLParsed.query['is_create_org'] = true;
URLParsed.query['code_challenge'] = configuration.fakeCodeChallenge;
URLParsed.query['code_challenge_method'] = 'S256';

const urlParsed = new URLSearchParams({
client_id: configuration.clientId || '',
redirect_uri: configuration.redirectUri || '',
client_secret: configuration.clientSecret || '',
scope: configuration.scope || '',
grant_type: 'authorization_code',
response_type: 'code',
start_page: 'registration',
state: configuration.fakeState || '',
is_create_org: true,
code_challenge: configuration.fakeCodeChallenge || '',
code_challenge_method: 'S256'
}).toString();

expect(InAppBrowser.openAuth).toHaveBeenCalledWith(
URLParsed.toString(),
`${configuration.authorizationEndpoint}?${urlParsed}`,
globalClient.redirectUri,
{
enableDefaultShare: false,
Expand Down Expand Up @@ -459,20 +481,22 @@ describe('KindeSDK', () => {
Constants.executionEnvironment = 'storeClient';

await globalClient.login();
const URLParsed = Url(`${configuration.issuer}/oauth2/auth`, true);
URLParsed.query['client_id'] = configuration.clientId;
URLParsed.query['redirect_uri'] = configuration.redirectUri;
URLParsed.query['client_secret'] = configuration.clientSecret;
URLParsed.query['scope'] = configuration.scope;
URLParsed.query['grant_type'] = 'authorization_code';
URLParsed.query['response_type'] = 'code';
URLParsed.query['start_page'] = 'login';
URLParsed.query['state'] = configuration.fakeState;
URLParsed.query['code_challenge'] = configuration.fakeCodeChallenge;
URLParsed.query['code_challenge_method'] = 'S256';

const urlParsed = new URLSearchParams({
client_id: configuration.clientId || '',
redirect_uri: configuration.redirectUri || '',
client_secret: configuration.clientSecret || '',
scope: configuration.scope || '',
grant_type: 'authorization_code',
response_type: 'code',
start_page: 'login',
state: configuration.fakeState || '',
code_challenge: configuration.fakeCodeChallenge || '',
code_challenge_method: 'S256'
}).toString();

expect(openAuthSessionAsync).toHaveBeenCalledWith(
URLParsed.toString(),
`${configuration.issuer}/oauth2/auth?${urlParsed}`,
globalClient.redirectUri
);
});
Expand All @@ -481,20 +505,22 @@ describe('KindeSDK', () => {
Constants.executionEnvironment = 'storeClient';

await globalClient.register();
const URLParsed = Url(configuration.authorizationEndpoint, true);
URLParsed.query['client_id'] = configuration.clientId;
URLParsed.query['redirect_uri'] = configuration.redirectUri;
URLParsed.query['client_secret'] = configuration.clientSecret;
URLParsed.query['scope'] = configuration.scope;
URLParsed.query['grant_type'] = 'authorization_code';
URLParsed.query['response_type'] = 'code';
URLParsed.query['start_page'] = 'registration';
URLParsed.query['state'] = configuration.fakeState;
URLParsed.query['code_challenge'] = configuration.fakeCodeChallenge;
URLParsed.query['code_challenge_method'] = 'S256';

const urlParsed = new URLSearchParams({
client_id: configuration.clientId || '',
redirect_uri: configuration.redirectUri || '',
client_secret: configuration.clientSecret || '',
scope: configuration.scope || '',
grant_type: 'authorization_code',
response_type: 'code',
start_page: 'registration',
state: configuration.fakeState || '',
code_challenge: configuration.fakeCodeChallenge || '',
code_challenge_method: 'S256'
}).toString();

expect(openAuthSessionAsync).toHaveBeenCalledWith(
URLParsed.toString(),
`${configuration.authorizationEndpoint}?${urlParsed}`,
globalClient.redirectUri
);
});
Expand All @@ -503,11 +529,11 @@ describe('KindeSDK', () => {
Constants.executionEnvironment = 'storeClient';

await globalClient.logout();
const URLParsed = Url(configuration.logoutEndpoint, true);
URLParsed.query['redirect'] = configuration.logoutRedirectUri;

expect(openAuthSessionAsync).toHaveBeenCalledWith(
URLParsed.toString(),
`${configuration.logoutEndpoint}?${new URLSearchParams({
redirect: configuration.logoutRedirectUri
}).toString()}`,
globalClient.redirectUri
);
});
Expand Down Expand Up @@ -548,21 +574,23 @@ describe('KindeSDK', () => {
test('[ExpoStorage] Create Organization', async () => {
Constants.executionEnvironment = 'storeClient';
await globalClient.createOrg();
const URLParsed = Url(configuration.authorizationEndpoint, true);
URLParsed.query['client_id'] = configuration.clientId;
URLParsed.query['redirect_uri'] = configuration.redirectUri;
URLParsed.query['client_secret'] = configuration.clientSecret;
URLParsed.query['scope'] = configuration.scope;
URLParsed.query['grant_type'] = 'authorization_code';
URLParsed.query['response_type'] = 'code';
URLParsed.query['start_page'] = 'registration';
URLParsed.query['state'] = configuration.fakeState;
URLParsed.query['is_create_org'] = true;
URLParsed.query['code_challenge'] = configuration.fakeCodeChallenge;
URLParsed.query['code_challenge_method'] = 'S256';

const urlParsed = new URLSearchParams({
client_id: configuration.clientId || '',
redirect_uri: configuration.redirectUri || '',
client_secret: configuration.clientSecret || '',
scope: configuration.scope || '',
grant_type: 'authorization_code',
response_type: 'code',
start_page: 'registration',
state: configuration.fakeState || '',
is_create_org: true,
code_challenge: configuration.fakeCodeChallenge || '',
code_challenge_method: 'S256'
}).toString();

expect(openAuthSessionAsync).toHaveBeenCalledWith(
URLParsed.toString(),
`${configuration.authorizationEndpoint}?${urlParsed}`,
globalClient.redirectUri
);
});
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,8 @@
"expo-web-browser": "12.8.2",
"expo-secure-store": "^12.1.1",
"jwt-decode": "^3.1.2",
"qs": "^6.11.0",
"react-native-inappbrowser-reborn": "^3.7.0",
"react-native-keychain": ">= 8.0",
"superagent": "^7.0.2",
"url-parse": "^1.5.10"
"react-native-keychain": ">= 8.0"
},
"devDependencies": {
"@babel/cli": "^7.0.0",
Expand Down
25 changes: 16 additions & 9 deletions src/SDK/KindeSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,13 @@ class KindeSDK extends runtime.BaseAPI {
await this.cleanUp();

if (isRevoke) {
const payload = new AuthorizationCode().buildBaseAuthenticateURL(
this
);
const payload = new URLSearchParams({
client_id: this.clientId,
redirect_uri: this.redirectUri,
client_secret: this.clientSecret || '',
scope: this.scope,
grant_type: 'authorization_code'
});

try {
await this.request({
Expand All @@ -206,10 +210,10 @@ class KindeSDK extends runtime.BaseAPI {
}
}

const URLParsed = Url(this.logoutEndpoint, true);
URLParsed.query['redirect'] = this.logoutRedirectUri;
const response = await openWebBrowser(
URLParsed.toString(),
this.logoutEndpoint +
'?' +
new URLSearchParams({ redirect: this.logoutRedirectUri }),
this.redirectUri,
authBrowserOptions || this.authBrowserOptions
);
Expand All @@ -235,10 +239,13 @@ class KindeSDK extends runtime.BaseAPI {

checkNotNull(url, 'URL');

const URLParsed = Url(String(url), true);
const { code, error, error_description } = URLParsed.query;
const params = new URL(url!).searchParams;

const code = params.get('code');
const error = params.get('error');
const errorDescription = params.get('error_description');
if (error) {
const msg = error_description ?? error;
const msg = errorDescription ?? error;
throw new UnAuthenticatedException(msg);
}
checkNotNull(code, 'code');
Expand Down
Loading

0 comments on commit 206f55c

Please sign in to comment.