-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: preventing PATs from creating PATs
- Loading branch information
Showing
6 changed files
with
81 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,35 @@ | ||
export const canCreateToken = (userScopes: string[], tokenScopes: string[]) => { | ||
return tokenScopes.every((scope) => userScopes.includes(scope)) | ||
import { TokenCreateError } from '@/modules/core/errors/user' | ||
import { Scopes } from '@speckle/shared' | ||
|
||
export const canCreateToken = (params: { | ||
userScopes: string[] | ||
tokenScopes: string[] | ||
strict?: boolean | ||
}) => { | ||
const { userScopes, tokenScopes, strict } = params | ||
const hasAllScopes = tokenScopes.every((scope) => userScopes.includes(scope)) | ||
if (!hasAllScopes) { | ||
if (!strict) return false | ||
throw new TokenCreateError( | ||
"You can't create a token with scopes that you don't have" | ||
) | ||
} | ||
|
||
return true | ||
} | ||
|
||
export const canCreatePAT = (params: { | ||
userScopes: string[] | ||
tokenScopes: string[] | ||
strict?: boolean | ||
}) => { | ||
const { tokenScopes, strict } = params | ||
if (tokenScopes.includes(Scopes.Tokens.Write)) { | ||
if (!strict) return false | ||
throw new TokenCreateError( | ||
"You can't create a personal access token with the tokens:write scope" | ||
) | ||
} | ||
|
||
return canCreateToken(params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters