Skip to content

Commit 9e8363e

Browse files
Update the redirect URL payload format (#21)
* Updated the redirectURI payload format * Updated the tests
1 parent 9a5f1d7 commit 9e8363e

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

js/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export const TLD: Record<string, string> = {
55
};
66

77
export const NEETO_URL_COMPONENT_REGEX = /neeto(\w+)/;
8+
export const NEETO_URL_PREFIX_REGEX = /^(https?:\/\/)?(www\.)?[\w-]+\./;
89

910
export const CLIENT_APPS = {
1011
cal: "Cal",

js/src/index.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import jwt from "jsonwebtoken";
2-
import { getClientAppName, getLoginUri, SearchParams } from "./utils.js";
2+
import {
3+
getClientAppName,
4+
getLoginUri,
5+
getRedirectUri,
6+
SearchParams,
7+
} from "./utils.js";
38

49
interface Options {
510
email: string;
@@ -48,7 +53,7 @@ class NeetoJWT {
4853

4954
const searchParams: SearchParams = {
5055
jwt: this.generateJWT(),
51-
redirect_uri: encodeURI(redirectUri),
56+
redirect_uri: getRedirectUri(redirectUri),
5257
client_app_name: getClientAppName(redirectUri),
5358
};
5459

js/src/utils.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { CLIENT_APPS, NEETO_URL_COMPONENT_REGEX, TLD } from "./constants.js";
1+
import {
2+
CLIENT_APPS,
3+
NEETO_URL_COMPONENT_REGEX,
4+
NEETO_URL_PREFIX_REGEX,
5+
TLD,
6+
} from "./constants.js";
27

38
export type SearchParams = {
49
jwt: string;
@@ -29,3 +34,13 @@ export const getClientAppName = (redirectUri: string) => {
2934

3035
return "Cal";
3136
};
37+
38+
export const getRedirectUri = (redirectUri: string) => {
39+
const match = redirectUri.match(NEETO_URL_PREFIX_REGEX);
40+
41+
if (match) {
42+
return encodeURI(redirectUri.replace(NEETO_URL_PREFIX_REGEX, ""));
43+
}
44+
45+
return encodeURI(getTopLevelDomain());
46+
};

js/test/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe("NeetoJWT", () => {
5353
expect(loginUrl).toContain("https://spinkart.neetoauth.com/users/auth/jwt");
5454
expect(loginUrl).toContain(`jwt=`);
5555
expect(loginUrl).toContain(
56-
`redirect_uri=${encodeURIComponent(redirectUri)}`
56+
`redirect_uri=${encodeURIComponent("neetocal.com/admin")}`
5757
);
5858
expect(loginUrl).toContain(`client_app_name=Cal`);
5959
});

0 commit comments

Comments
 (0)