File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export const TLD: Record<string, string> = {
66
77export const USER_LOGIN_PATH = "/users/auth/jwt" ;
88export const CONSUMER_LOGIN_PATH = "/consumers/auth/jwt" ;
9+ export const CONSUMER_WORKSPACE = "app" ;
910
1011export const NEETO_URL_COMPONENT_REGEX = / n e e t o ( \w + ) / ;
1112export const NEETO_URL_PREFIX_REGEX = / ^ ( h t t p s ? : \/ \/ ) ? ( w w w \. ) ? [ \w - ] + \. / ;
Original file line number Diff line number Diff line change 11import jwt from "jsonwebtoken" ;
2+ import { CONSUMER_WORKSPACE } from "./constants.js" ;
23import type { Scope } from "./types.js" ;
34import {
45 getClientAppName ,
@@ -14,8 +15,6 @@ interface Options {
1415 scope ?: Scope ;
1516}
1617
17- const CONSUMER_WORKSPACE = "app" ;
18-
1918class NeetoJWT {
2019 private email : string ;
2120 private workspace : string ;
Original file line number Diff line number Diff line change 11import {
22 CLIENT_APPS ,
33 CONSUMER_LOGIN_PATH ,
4+ CONSUMER_WORKSPACE ,
45 NEETO_URL_COMPONENT_REGEX ,
56 NEETO_URL_PREFIX_REGEX ,
67 TLD ,
@@ -22,9 +23,11 @@ export const getLoginUri = (
2223 const protocol =
2324 process . env . NEETO_JWT_ENV === "development" ? "http" : "https" ;
2425 const params = new URLSearchParams ( searchParams ) . toString ( ) ;
25- const path = scope === "consumer" ? CONSUMER_LOGIN_PATH : USER_LOGIN_PATH ;
26+ const isConsumer = scope === "consumer" ;
27+ const host = isConsumer ? CONSUMER_WORKSPACE : workspace ;
28+ const path = isConsumer ? CONSUMER_LOGIN_PATH : USER_LOGIN_PATH ;
2629
27- return `${ protocol } ://${ workspace } ${ getTopLevelDomain ( ) } ${ path } ?${ params } ` ;
30+ return `${ protocol } ://${ host } ${ getTopLevelDomain ( ) } ${ path } ?${ params } ` ;
2831} ;
2932
3033export const getTopLevelDomain = ( ) => {
Original file line number Diff line number Diff line change @@ -152,17 +152,23 @@ describe("NeetoJWT", () => {
152152 }
153153 } ) ;
154154
155- it ( "should honour an explicit consumer- scope workspace override" , ( ) => {
155+ it ( "should send consumer scope to the global app host regardless of workspace override, while preserving the workspace claim " , ( ) => {
156156 const neetoJWT = new NeetoJWT ( {
157157 email,
158158 privateKey,
159- workspace : "staging-app " ,
159+ workspace : "spinkart " ,
160160 scope : "consumer" ,
161161 } ) ;
162162 const loginUrl = neetoJWT . generateLoginUrl ( "http://partner.example.com/cb" ) ;
163163 expect ( loginUrl ) . toContain (
164- "https://staging- app.neetoauth.com/consumers/auth/jwt"
164+ "https://app.neetoauth.com/consumers/auth/jwt"
165165 ) ;
166+
167+ const token = new URL ( loginUrl ) . searchParams . get ( "jwt" ) as string ;
168+ const payload = JSON . parse (
169+ Buffer . from ( token . split ( "." ) [ 1 ] , "base64" ) . toString ( )
170+ ) ;
171+ expect ( payload . workspace ) . toBe ( "spinkart" ) ;
166172 } ) ;
167173
168174 it ( "should not double-encode the consumer redirect URI" , ( ) => {
You can’t perform that action at this time.
0 commit comments