forked from ory/elements
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
258 additions
and
12 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
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
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,38 @@ | ||
import { OAuth2ConsentRequest } from "@ory/client" | ||
import { | ||
AuthPage, | ||
loginFixture, | ||
recoveryFixture, | ||
registrationFixture, | ||
twoFactorLoginFixture, | ||
verificationFixture, | ||
} from "@ory/elements-test" | ||
import { expect, test } from "@playwright/experimental-ct-react" | ||
import { ComponentProps } from "react" | ||
import { ConsentPage } from "../../test/ConsentPage" | ||
import { UserConsentCard } from "./user-consent-card" | ||
|
||
test("ory consent card login flow", async ({ mount }) => { | ||
const defaults = { | ||
csrfToken: "csrfToken_example", | ||
action: "consent", | ||
client_name: "Best App", | ||
client: { | ||
tos_uri: "https://test_tos_uri/", | ||
policy_uri: "https://test_policy_uri/", | ||
}, | ||
consent: {} as OAuth2ConsentRequest, | ||
requested_scope: ["test_scope1", "test_scope2", "test_scope3"], | ||
} | ||
|
||
const component = await mount(<UserConsentCard {...defaults} />) | ||
|
||
const consentComponent = new ConsentPage(component) | ||
|
||
await consentComponent.expectScopeFields(defaults.requested_scope) | ||
await consentComponent.expectUris([ | ||
"https://test_tos_uri/", | ||
"https://test_policy_uri/", | ||
]) | ||
await consentComponent.expectAllowSubmit() | ||
}) |
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,112 @@ | ||
import { gridStyle, typographyStyle } from "../../theme" | ||
import { Button } from "../button" | ||
import { ButtonLink } from "../button-link" | ||
import { Card } from "../card" | ||
import { Typography } from "../typography" | ||
|
||
import "../../assets/fontawesome.min.css" | ||
import "../../assets/fa-solid.min.css" | ||
import { Checkbox } from "../checkbox" | ||
import { OAuth2Client, OAuth2ConsentRequest } from "@ory/client" | ||
import { style } from "@vanilla-extract/css" | ||
import { recipe } from "@vanilla-extract/recipes" | ||
import { Divider } from "../divider" | ||
|
||
export type UserConsentCardProps = { | ||
csrfToken: string | ||
consent: OAuth2ConsentRequest | ||
cardImage?: string | React.ReactElement | ||
client_name: string | ||
requested_scope?: string[] | ||
client?: OAuth2Client | ||
action: string | ||
} | ||
|
||
export const UserConsentCard = ({ | ||
csrfToken, | ||
consent, | ||
cardImage, | ||
client_name = "Unnamed Client", | ||
requested_scope = [], | ||
client, | ||
action, | ||
}: UserConsentCardProps) => { | ||
return ( | ||
<Card | ||
heading={ | ||
<div style={{ textAlign: "center" }}> | ||
<Typography type="bold">{client_name}</Typography> | ||
</div> | ||
} | ||
image={cardImage} | ||
> | ||
<form action={action} method="post"> | ||
<input type="hidden" name="_csrf" value={csrfToken} /> | ||
<input | ||
type="hidden" | ||
name="consent_challenge" | ||
value={consent?.challenge} | ||
/> | ||
<div className={gridStyle({ gap: 16 })}> | ||
<div className={gridStyle({ gap: 4 })} style={{ marginBottom: 16 }}> | ||
<Typography> | ||
The application requests access to the following permissions: | ||
</Typography> | ||
</div> | ||
<div className={gridStyle({ gap: 4 })}> | ||
{requested_scope.map((scope) => ( | ||
<Checkbox label={scope} value={scope} name="grant_scope" /> | ||
))} | ||
</div> | ||
<div className={gridStyle({ gap: 4 })}> | ||
<Typography size="xsmall"> | ||
Only grant permissions if you trust this site or app. You do not | ||
need to accept all permissions. | ||
</Typography> | ||
</div> | ||
<div className={gridStyle({ direction: "row" })}> | ||
{client?.policy_uri && ( | ||
<a href={client.policy_uri} target="_blank"> | ||
<Typography size="xsmall">Privacy Policy</Typography> | ||
</a> | ||
)} | ||
{client?.tos_uri && ( | ||
<a href={client.tos_uri} target="_blank"> | ||
<Typography size="xsmall">Terms of Service</Typography> | ||
</a> | ||
)} | ||
</div> | ||
<Divider /> | ||
<div className={gridStyle({ gap: 8 })}> | ||
<Checkbox label="Remember my decision" /> | ||
<Typography size="xsmall"> | ||
Remember this decision for next time. The application will not be | ||
able to ask for additional permissions without your consent. | ||
</Typography> | ||
</div> | ||
<div | ||
className={gridStyle({ direction: "row" })} | ||
style={{ justifyContent: "space-between", alignItems: "center" }} | ||
> | ||
<Button | ||
type="submit" | ||
id="reject" | ||
name="consent_action" | ||
value="reject" | ||
variant="error" | ||
header="Deny" | ||
/> | ||
<Button | ||
type="submit" | ||
id="accept" | ||
name="consent_action" | ||
value="accept" | ||
variant="semibold" | ||
header="Allow" | ||
/> | ||
</div> | ||
</div> | ||
</form> | ||
</Card> | ||
) | ||
} |
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,26 @@ | ||
import { ComponentProps } from "react" | ||
import { ComponentMeta, Story } from "@storybook/react" | ||
|
||
import { Container } from "../storyhelper" | ||
import { UserConsentCard } from "../../react-components" | ||
import logo from "../assets/logo.svg" | ||
|
||
export default { | ||
title: "Ory/UserConsentCard", | ||
component: UserConsentCard, | ||
} as ComponentMeta<typeof UserConsentCard> | ||
|
||
const Template: Story<ComponentProps<typeof UserConsentCard>> = ( | ||
args: ComponentProps<typeof UserConsentCard>, | ||
) => ( | ||
<Container> | ||
<UserConsentCard {...args} /> | ||
</Container> | ||
) | ||
|
||
export const ConsentCard = Template.bind({}) | ||
ConsentCard.args = { | ||
cardImage: logo, | ||
requested_scope: ["openid", "test_scope"], | ||
client: { tos_uri: "example.com/", policy_uri: "example.com/" }, | ||
} |
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,37 @@ | ||
import { UiNode } from "@ory/client" | ||
import { expect, Locator } from "@playwright/test" | ||
import { Traits } from "./types" | ||
import { inputNodesToRecord, isUiNode } from "./Utils" | ||
|
||
export class ConsentPage { | ||
readonly locator: Locator | ||
readonly formFields: Record<string, Locator> = {} | ||
|
||
constructor(locator: Locator) { | ||
this.locator = locator | ||
} | ||
|
||
async expectScopeFields(scopes: string[]) { | ||
for (const scope of scopes) { | ||
await expect( | ||
this.locator.locator(`input[type="checkbox"][value="${scope}"]`), | ||
).toBeVisible() | ||
} | ||
} | ||
|
||
async expectUris(uris: string[]) { | ||
for (const uri of uris) { | ||
await expect(this.locator.locator(`a[href="${uri}"]`)).toBeVisible() | ||
} | ||
} | ||
|
||
async expectAllowSubmit() { | ||
await expect( | ||
this.locator.locator('button[value="accept"][type="submit"]'), | ||
).toBeVisible() | ||
} | ||
|
||
async submitForm() { | ||
await this.locator.locator('[type="submit"]').click() | ||
} | ||
} |
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