-
Notifications
You must be signed in to change notification settings - Fork 173
feat: Add support for riskAssessment
#1217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kushalshit27
merged 28 commits into
auth0:master
from
josh-cain:addRiskAssessmentConfig
Dec 22, 2025
Merged
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
9f6141b
feat: riskAssessments integration
josh-cain 2bf229d
feedback: nest new device settings under riskAssessment
josh-cain 659aed8
Merge branch 'master' into addRiskAssessmentConfig
josh-cain 9f11f9d
Merge branch 'master' into addRiskAssessmentConfig
josh-cain a3145bc
feedbadck: null check for status code
josh-cain 8b30faf
feedback: remove useless catch
josh-cain 98b09de
remove additional references to previous/legacy format
josh-cain c83d43f
null checkery
josh-cain 318b968
shorthand
josh-cain 6818cb8
feedback: singular-ize riskAssessments
josh-cain 3e38f5c
Update docs/resource-specific-documentation.md
josh-cain c73ad14
Update src/tools/constants.ts
josh-cain 6c9931a
feedback: more renaming
josh-cain b64421f
fix: tests should reflect singular naming too
josh-cain 11b651b
Merge branch 'master' into addRiskAssessmentConfig
kushalshit27 863a41e
Merge branch 'master' into addRiskAssessmentConfig
kushalshit27 cf25eea
feat: update risk assessment schema structure
kushalshit27 3c7b539
feat: update risk assessment structure and tests
kushalshit27 63a5f2d
feat: update risk assessment configuration and examples
kushalshit27 bb528f1
update e2e
kushalshit27 168018a
feat: update risk assessment types and remove settings.json
kushalshit27 592fc28
update e2e
kushalshit27 fcf3bbb
update e2e
kushalshit27 9b5f240
E2E add cross_origin_authentication to client configurations test-data
kushalshit27 53ce517
E2E updated
kushalshit27 9206aa6
E2E:enable cross_origin_authentication for Deploy CLI client on test-…
kushalshit27 c499cb0
e2e update
kushalshit27 4422674
e2e update
kushalshit27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "enabled": false | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import path from 'path'; | ||
| import fs from 'fs-extra'; | ||
| import { constants } from '../../../tools'; | ||
| import { dumpJSON, existsMustBeDir, isFile, loadJSON } from '../../../utils'; | ||
| import { DirectoryHandler } from '.'; | ||
| import DirectoryContext from '..'; | ||
| import { ParsedAsset, Asset } from '../../../types'; | ||
|
|
||
| type ParsedRiskAssessment = ParsedAsset<'riskAssessment', Asset>; | ||
|
|
||
| function parse(context: DirectoryContext): ParsedRiskAssessment { | ||
| const riskAssessmentsDirectory = path.join( | ||
| context.filePath, | ||
| constants.RISK_ASSESSMENTS_DIRECTORY | ||
| ); | ||
| const riskAssessmentsFile = path.join(riskAssessmentsDirectory, 'settings.json'); | ||
|
|
||
| if (!existsMustBeDir(riskAssessmentsDirectory)) { | ||
| return { riskAssessment: null }; | ||
| } | ||
|
|
||
| if (!isFile(riskAssessmentsFile)) { | ||
| return { riskAssessment: null }; | ||
| } | ||
|
|
||
| const riskAssessment = loadJSON(riskAssessmentsFile, { | ||
| mappings: context.mappings, | ||
| disableKeywordReplacement: context.disableKeywordReplacement, | ||
| }); | ||
|
|
||
| return { | ||
| riskAssessment, | ||
| }; | ||
| } | ||
|
|
||
| async function dump(context: DirectoryContext): Promise<void> { | ||
| const { riskAssessment } = context.assets; | ||
|
|
||
| if (!riskAssessment) return; | ||
|
|
||
| const riskAssessmentsDirectory = path.join( | ||
| context.filePath, | ||
| constants.RISK_ASSESSMENTS_DIRECTORY | ||
| ); | ||
| const riskAssessmentsFile = path.join(riskAssessmentsDirectory, 'settings.json'); | ||
|
|
||
| fs.ensureDirSync(riskAssessmentsDirectory); | ||
| dumpJSON(riskAssessmentsFile, riskAssessment); | ||
| } | ||
|
|
||
| const riskAssessmentsHandler: DirectoryHandler<ParsedRiskAssessment> = { | ||
| parse, | ||
| dump, | ||
| }; | ||
|
|
||
| export default riskAssessmentsHandler; |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { YAMLHandler } from '.'; | ||
| import YAMLContext from '..'; | ||
| import { Asset, ParsedAsset } from '../../../types'; | ||
|
|
||
| type ParsedRiskAssessment = ParsedAsset<'riskAssessment', Asset>; | ||
|
|
||
| async function parse(context: YAMLContext): Promise<ParsedRiskAssessment> { | ||
| const { riskAssessment } = context.assets; | ||
|
|
||
| if (!riskAssessment) return { riskAssessment: null }; | ||
|
|
||
| return { | ||
| riskAssessment, | ||
| }; | ||
| } | ||
|
|
||
| async function dump(context: YAMLContext): Promise<ParsedRiskAssessment> { | ||
| const { riskAssessment } = context.assets; | ||
|
|
||
| if (!riskAssessment) return { riskAssessment: null }; | ||
|
|
||
| return { | ||
| riskAssessment, | ||
| }; | ||
| } | ||
|
|
||
| const riskAssessmentsHandler: YAMLHandler<ParsedRiskAssessment> = { | ||
| parse, | ||
| dump, | ||
| }; | ||
|
|
||
| export default riskAssessmentsHandler; |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| import DefaultAPIHandler from './default'; | ||
| import { Assets } from '../../../types'; | ||
|
|
||
| export const schema = { | ||
| type: 'object', | ||
| properties: { | ||
| enabled: { | ||
| type: 'boolean', | ||
| description: 'Whether or not risk assessment is enabled.', | ||
| }, | ||
| newDevice: { | ||
| type: 'object', | ||
| properties: { | ||
| remember_for: { | ||
| type: 'number', | ||
| description: 'Length of time to remember devices for, in days.', | ||
| }, | ||
| }, | ||
| required: ['remember_for'], | ||
| }, | ||
| }, | ||
| required: ['enabled'], | ||
| }; | ||
|
|
||
| export type RiskAssessmentsSettings = { | ||
| enabled: boolean; | ||
| newDevice?: { | ||
| remember_for: number; | ||
| }; | ||
| }; | ||
|
|
||
| export default class RiskAssessmentsHandler extends DefaultAPIHandler { | ||
| existing: RiskAssessmentsSettings | null; | ||
|
|
||
| constructor(config: DefaultAPIHandler) { | ||
| super({ | ||
| ...config, | ||
| type: 'riskAssessment', | ||
| }); | ||
| } | ||
|
|
||
| async getType(): Promise<RiskAssessmentsSettings> { | ||
| if (this.existing) { | ||
| return this.existing; | ||
| } | ||
|
|
||
| try { | ||
| const [settings, newDeviceSettings] = await Promise.all([ | ||
| this.client.riskAssessments.getSettings(), | ||
| this.client.riskAssessments.getNewDeviceSettings().catch((err) => { | ||
| if (err?.statusCode === 404) return { data: { remember_for: 0 } }; | ||
| throw err; | ||
| }), | ||
| ]); | ||
|
|
||
| this.existing = { | ||
| enabled: settings.data.enabled, | ||
| ...(newDeviceSettings.data.remember_for > 0 && { | ||
| newDevice: { | ||
| remember_for: newDeviceSettings.data.remember_for, | ||
| }, | ||
| }), | ||
| }; | ||
| return this.existing; | ||
| } catch (err) { | ||
| if (err.statusCode === 404) return { enabled: false }; | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| async processChanges(assets: Assets): Promise<void> { | ||
| const { riskAssessment } = assets; | ||
|
|
||
| // Non-existing section means it doesn't need to be processed | ||
| if (!riskAssessment) { | ||
| return; | ||
| } | ||
|
|
||
| const updates: Promise<unknown>[] = []; | ||
|
|
||
| // Update main settings (enabled flag) | ||
| const settings = { | ||
| enabled: riskAssessment.enabled as boolean, | ||
| }; | ||
| updates.push(this.client.riskAssessments.updateSettings(settings)); | ||
|
|
||
| // Update new device settings if provided | ||
| if (riskAssessment.newDevice) { | ||
| const newDeviceSettings = { | ||
| remember_for: riskAssessment.newDevice.remember_for as number, | ||
| }; | ||
| updates.push(this.client.riskAssessments.updateNewDeviceSettings(newDeviceSettings)); | ||
| } | ||
|
|
||
| await Promise.all(updates); | ||
| this.updated += 1; | ||
| this.didUpdate(riskAssessment); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.