Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielRivers committed Jan 16, 2025
1 parent 424c864 commit a27650e
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 15 deletions.
119 changes: 105 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pnpm install @kinde/infrastructure

## Usage

### Methods
### Workflow Methods

`idTokenCustomClaims` - Define and set custom claims on the id token

Expand All @@ -29,10 +29,46 @@ pnpm install @kinde/infrastructure

`fetch` - Sent a request to external API

`secureFetch` - Sent an encypted request to external API

`getEnvironmentVariable` - Get Environment variable from Kinde secrets

`createKindeAPI` - Create handler to call the Kinde management SDK

### Custom Pages Methods

`getKindeWidget` - Places the kinde widget on the page

`getKindeNonce` - Places the generated Nonce on your page for increased security

`getKindeRequiredCSS` - Inserts the required CSS

`getKindeRequiredJS` - Inserts the required JS

`getKindeCSRF` - Places the generated CSRF on your page for increased security

`getKindeRegisterUrl` or `getKindeSignUpUrl` - Gets the registration Url

`getKindeLoginUrl` or `getKindeSignInUrl`- Gets the login Url

`getLogoUrl` - Gets the organisations logo Url

`getDarkModeLogoUrl` - gets the organisations dark mode logo Url

`getSVGFaviconUrl` - gets the organistaions SVG favicon

`getFallbackFaviconUrl` - geths the organisations fallback favicon

`setKindeDesignerCustomProperties` - Update styling of the Kinde widget

- baseBackgroundColor
- baseLinkColor
- buttonBorderRadius,
- primaryButtonBackgroundColor
- primaryButtonColor
- cardBorderRadius
- inputBorderRadius

### Workflow Event

#### User token generation
Expand Down Expand Up @@ -95,6 +131,63 @@ pnpm install @kinde/infrastructure
}
```

#### On new password provided

```json
{
"request": {
"ip": "1.2.3.4",
"auth": {
"audience": ["https://api.example.com/v1"]
}
},
"context": {
"auth": {
"firstPassword": "somesecurepassword",
"secondPassword": "somesecurepassword",
"newPasswordReason": "reset",
},
"domains": {
"kindeDomain": "https://mykindebusiness.kinde.com"
},
"workflow": {
"trigger": "user:new_password_provided"
},
"application": {
"clientId": "f77dbc..."
}
}
}
```

#### On existing password provided

```json
{
"request": {
"ip": "1.2.3.4",
"auth": {
"audience": ["https://api.example.com/v1"]
}
},
"context": {
"auth": {
"password": "somesecurepassword"
},
"domains": {
"kindeDomain": "https://mykindebusiness.kinde.com"
},
"workflow": {
"trigger": "user:existing_password_provided"
},
"application": {
"clientId": "f77dbc..."
}
}
}
```


### Examples

#### Customise tokens
Expand All @@ -121,17 +214,15 @@ export const workflowSettings: WorkflowSettings = {
},
};

export default {
async handle(event: onUserTokenGeneratedEvent) {
const accessToken = accessTokenCustomClaims<{
hello: string;
ipAddress: string;
}>();
export default async function (event: onUserTokenGeneratedEvent) {
const accessToken = accessTokenCustomClaims<{
hello: string;
ipAddress: string;
}>();

accessToken.hello = "Hello there!";
accessToken.ipAddress = event.request.ip;
},
};
accessToken.hello = "Hello there!";
accessToken.ipAddress = event.request.ip;
},
```

This will result with two new extra claims added to the AccessToken
Expand All @@ -154,7 +245,7 @@ kinde.accessToken
```

```typescript
async handle(event: onUserTokenGeneratedEvent) {
export default async function (event: onUserTokenGeneratedEvent) {
if (event.request.ip.startsWith('192')) {
denyAccess("You are not allowed to access this resource");
}
Expand All @@ -175,7 +266,7 @@ url
```

```typescript
async handle(event: onUserTokenGeneratedEvent) {
export default async function (event: onUserTokenGeneratedEvent) {
const ipInfoToken = getEnvironmentVariable('IP_INFO_TOKEN')?.value

const { data: ipDetails } = await fetch(`https://ipinfo.io/${event.request.ip}?token=${ipInfoToken}`, {
Expand Down Expand Up @@ -219,7 +310,7 @@ url
```

```typescript
async handle(event: onUserTokenGeneratedEvent) {
export default async function (event: onUserTokenGeneratedEvent) {
const orgCode = event.context.organization.code;
const userId = event.context.user.id;

Expand Down
2 changes: 1 addition & 1 deletion lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export const setKindeDesignerCustomProperties = ({
primaryButtonColor,
cardBorderRadius,
inputBorderRadius,
}: KindeDesignerCustomProperties) => {
}: KindeDesignerCustomProperties): string => {
if (
!coloursValid(
baseBackgroundColor,
Expand Down

0 comments on commit a27650e

Please sign in to comment.