-
Notifications
You must be signed in to change notification settings - Fork 1
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
Extract API implementations from Post Login API #12
Merged
+1,333
−318
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6b71b99
Extract access token api
matt-wratt 8ff15c2
Extract mock access api
matt-wratt c9410d7
Extract mock authentication api
matt-wratt d8e232d
Extract mock id-token api
matt-wratt 80ec891
Extract mock multifactor api
matt-wratt 7febfa0
Extract mock redirect api
matt-wratt 67c2fbb
Extract mock user api
matt-wratt beca9d9
Extract mock SAML response api
matt-wratt 4f18378
Extract mock validation api
matt-wratt 6b779b8
Extract mock rules api
matt-wratt 1da719d
Remove unused imports
matt-wratt 572dc6e
Update examples
matt-wratt 042fc6f
Fix failing test
matt-wratt 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
interface AccessTokenMock { | ||
build: <T>(api: T) => { | ||
addScope: (name: string) => T; | ||
removeScope: (name: string) => T; | ||
setCustomClaim: (name: string, value: unknown) => T; | ||
}; | ||
state: { | ||
scopes: string[]; | ||
claims: Record<string, unknown>; | ||
}; | ||
} | ||
|
||
interface CredentialsExchangeAccessTokenMock { | ||
build: <T>(api: T) => { | ||
setCustomClaim: (name: string, value: unknown) => T; | ||
}; | ||
state: { | ||
claims: Record<string, unknown>; | ||
}; | ||
} | ||
|
||
export function accessTokenMock(flow: "CredentialsExchange"): CredentialsExchangeAccessTokenMock; | ||
export function accessTokenMock(flow: string): AccessTokenMock; | ||
export function accessTokenMock(flow: string) { | ||
switch(flow) { | ||
case "CredentialsExchange": { | ||
const state = { | ||
claims: {} as Record<string, unknown>, | ||
}; | ||
|
||
const build = <T>(api: T) => ({ | ||
setCustomClaim: (name: string, value: unknown) => { | ||
state.claims[name] = value; | ||
return api; | ||
}, | ||
}) | ||
|
||
return { build, state }; | ||
} | ||
|
||
default: { | ||
const state = { | ||
scopes: [] as string[], | ||
claims: {} as Record<string, unknown>, | ||
}; | ||
|
||
const build = <T>(api: T) => ({ | ||
addScope: (name: string) => { | ||
state.scopes = [ | ||
...new Set(state.scopes).add(name), | ||
]; | ||
|
||
return api; | ||
}, | ||
|
||
removeScope: (name: string) => { | ||
state.scopes = state.scopes.filter( | ||
(value) => value !== name | ||
); | ||
|
||
return api; | ||
}, | ||
|
||
setCustomClaim: (name: string, value: unknown) => { | ||
state.claims[name] = value; | ||
return api; | ||
}, | ||
}) | ||
|
||
return { build, state }; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
interface AccessMock { | ||
build: <API>(api: API) => { | ||
deny: (reason: string) => API; | ||
}; | ||
state: { | ||
denied: false | { reason: string }; | ||
}; | ||
}; | ||
|
||
interface CredentialsExchangeAccessMock { | ||
build: <API>(api: API) => { | ||
deny: (code: string, reason: string) => API; | ||
}; | ||
state: { | ||
denied: false | { code: string; reason: string }; | ||
}; | ||
}; | ||
|
||
export function accessMock(flow: "CredentialsExchange"): CredentialsExchangeAccessMock; | ||
export function accessMock(flow: string): AccessMock; | ||
export function accessMock(flow: string) { | ||
switch(flow) { | ||
case "CredentialsExchange": { | ||
const state = { | ||
denied: false as false | { code: string; reason: string }, | ||
}; | ||
|
||
const build = <API>(api: API) => ({ | ||
deny: (code: string, reason: string) => { | ||
state.denied = { code, reason }; | ||
return api; | ||
}, | ||
}); | ||
|
||
return { build, state }; | ||
} | ||
|
||
default: { | ||
const state = { | ||
denied: false as false | { reason: string }, | ||
}; | ||
|
||
const build = <API>(api: API) => ({ | ||
deny: (reason: string) => { | ||
state.denied = { reason }; | ||
return api; | ||
}, | ||
}); | ||
|
||
return { build, state }; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Factor } from "../../types"; | ||
|
||
export interface FactorList { | ||
allOptions: Factor[]; | ||
default: Factor | undefined; | ||
} | ||
|
||
export function authenticationMock(_flow: string, { userId }: { userId: string }) { | ||
let numCallsToSetPrimaryUser = 0; | ||
|
||
const state = { | ||
primaryUserId: userId, | ||
challenge: false as false | FactorList, | ||
enrollment: false as false | FactorList, | ||
newlyRecordedMethods: [] as string[], | ||
}; | ||
|
||
const build = <T>(api: T) => ({ | ||
challengeWith: (factor: Factor, options?: { additionalFactors?: Factor[] }) => { | ||
const additionalFactors = options?.additionalFactors ?? []; | ||
|
||
state.challenge = { | ||
allOptions: [factor, ...additionalFactors], | ||
default: factor, | ||
}; | ||
}, | ||
challengeWithAny(factors: Factor[]) { | ||
state.challenge = { | ||
allOptions: factors, | ||
default: undefined, | ||
}; | ||
}, | ||
enrollWith: (factor: Factor, options?: { additionalFactors?: Factor[] }) => { | ||
const additionalFactors = options?.additionalFactors ?? []; | ||
|
||
state.enrollment = { | ||
allOptions: [factor, ...additionalFactors], | ||
default: factor, | ||
}; | ||
}, | ||
enrollWithAny(factors: Factor[]) { | ||
state.enrollment = { | ||
allOptions: factors, | ||
default: undefined, | ||
}; | ||
}, | ||
setPrimaryUser: (primaryUserId: string) => { | ||
numCallsToSetPrimaryUser++; | ||
|
||
if (numCallsToSetPrimaryUser > 1) { | ||
throw new Error( | ||
"`authentication.setPrimaryUser` can only be set once per transaction" | ||
); | ||
} | ||
|
||
state.primaryUserId = primaryUserId; | ||
}, | ||
recordMethod: (providerUrl: string) => { | ||
state.newlyRecordedMethods.push(providerUrl); | ||
return api; | ||
}, | ||
}); | ||
|
||
return { state, build }; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export function idTokenMock(flow: string) { | ||
const state = { | ||
claims: {} as Record<string, unknown>, | ||
}; | ||
|
||
const build = <T>(api: T) => ({ | ||
setCustomClaim: (name: string, value: unknown) => { | ||
state.claims[name] = value; | ||
return api; | ||
}, | ||
}); | ||
|
||
return { state, build }; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { MultifactorEnableOptions } from "../../types"; | ||
|
||
export function multifactorMock(flow: string) { | ||
const state = { | ||
enabled: false as false | { provider: string; options?: MultifactorEnableOptions }, | ||
}; | ||
|
||
const build = <T>(api: T) => ({ | ||
enable: (provider: string, options?: MultifactorEnableOptions) => { | ||
state.enabled = { provider, options }; | ||
return api; | ||
}, | ||
}); | ||
|
||
return { state, build }; | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll revert this in the future (e.g. with a Proxy object) as this just creates an unnecessary property to have to type. See #19.