File tree 6 files changed +34
-6
lines changed
packages/service-utils/src
6 files changed +34
-6
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @thirdweb-dev/service-utils " : patch
3
+ ---
4
+
5
+ allow passing ` null ` to service scope, do not validate domains/bundleids when using secretKey auth method
Original file line number Diff line number Diff line change @@ -16,14 +16,17 @@ export type PolicyResult = {
16
16
17
17
export type CoreServiceConfig = {
18
18
apiUrl : string ;
19
- serviceScope : ServiceName ;
19
+ // if EXPLICITLY set to null, service will not be checked for authorization
20
+ // this is meant for services that are not possible to be turned off by users, such as "social" and "analytics"
21
+ serviceScope : ServiceName | null ;
20
22
serviceApiKey : string ;
21
23
serviceAction ?: string ;
22
24
useWalletAuth ?: boolean ;
23
25
includeUsage ?: boolean ;
24
26
} ;
25
27
26
28
export type TeamAndProjectResponse = {
29
+ authMethod : "secretKey" | "publishableKey" | "jwt" | "teamId" ;
27
30
team : TeamResponse ;
28
31
project ?: ProjectResponse | null ;
29
32
} ;
@@ -42,11 +45,11 @@ export type TeamResponse = {
42
45
name : string ;
43
46
slug : string ;
44
47
image : string | null ;
45
- billingPlan : string ;
48
+ billingPlan : "free" | "starter" | "growth" | "pro" ;
46
49
createdAt : Date ;
47
50
updatedAt : Date | null ;
48
51
billingEmail : string | null ;
49
- billingStatus : string | null ;
52
+ billingStatus : "noPayment" | "validPayment" | "invalidPayment" | null ;
50
53
growthTrialEligible : boolean | null ;
51
54
enabledScopes : ServiceName [ ] ;
52
55
} ;
Original file line number Diff line number Diff line change @@ -12,18 +12,25 @@ export function authorizeClient(
12
12
teamAndProjectResponse : TeamAndProjectResponse ,
13
13
) : AuthorizationResult {
14
14
const { origin, bundleId } = authOptions ;
15
- const { team, project } = teamAndProjectResponse ;
15
+ const { team, project, authMethod } = teamAndProjectResponse ;
16
16
17
17
const authResult : AuthorizationResult = {
18
18
authorized : true ,
19
19
team,
20
20
project,
21
+ authMethod,
21
22
} ;
22
23
24
+ // if there's no project, we'll return the authResult (JWT or teamId auth)
23
25
if ( ! project ) {
24
26
return authResult ;
25
27
}
26
28
29
+ if ( authMethod === "secretKey" ) {
30
+ // if the auth was done using secretKey, we do not want to enforce domains or bundleIds
31
+ return authResult ;
32
+ }
33
+
27
34
// check for public restrictions
28
35
if ( project . domains . includes ( "*" ) ) {
29
36
return authResult ;
Original file line number Diff line number Diff line change @@ -148,5 +148,6 @@ export async function authorize(
148
148
authorized : true ,
149
149
team : teamAndProjectResponse . team ,
150
150
project : teamAndProjectResponse . project ,
151
+ authMethod : clientAuth . authMethod ,
151
152
} ;
152
153
}
Original file line number Diff line number Diff line change @@ -5,7 +5,16 @@ export function authorizeService(
5
5
teamAndProjectResponse : TeamAndProjectResponse ,
6
6
serviceConfig : CoreServiceConfig ,
7
7
) : AuthorizationResult {
8
- const { team, project } = teamAndProjectResponse ;
8
+ const { team, project, authMethod } = teamAndProjectResponse ;
9
+
10
+ if ( serviceConfig . serviceScope === null ) {
11
+ // if explicitly set to null, we do not want to check for service level authorization
12
+ return {
13
+ authorized : true ,
14
+ team,
15
+ authMethod,
16
+ } ;
17
+ }
9
18
10
19
if ( ! team . enabledScopes . includes ( serviceConfig . serviceScope ) ) {
11
20
return {
@@ -21,6 +30,7 @@ export function authorizeService(
21
30
return {
22
31
authorized : true ,
23
32
team,
33
+ authMethod,
24
34
} ;
25
35
}
26
36
@@ -57,5 +67,6 @@ export function authorizeService(
57
67
authorized : true ,
58
68
team,
59
69
project,
70
+ authMethod,
60
71
} ;
61
72
}
Original file line number Diff line number Diff line change @@ -43,14 +43,15 @@ export const validTeamResponse: TeamResponse = {
43
43
updatedAt : new Date ( "2024-06-01" ) ,
44
44
billingPlan : "free" ,
45
45
billingEmail : "test@example.com" ,
46
- billingStatus : "noCustomer " ,
46
+ billingStatus : "noPayment " ,
47
47
growthTrialEligible : false ,
48
48
enabledScopes : [ "storage" , "rpc" , "bundler" ] ,
49
49
} ;
50
50
51
51
export const validTeamAndProjectResponse : TeamAndProjectResponse = {
52
52
team : validTeamResponse ,
53
53
project : validProjectResponse ,
54
+ authMethod : "publishableKey" ,
54
55
} ;
55
56
56
57
export const validServiceConfig : CoreServiceConfig = {
You can’t perform that action at this time.
0 commit comments