### Start Application
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/application-setup.mdx
Command to start the React development server. This command assumes you have Node.js and Yarn installed.
```bash
yarn start
```
--------------------------------
### Clone Demo Repository
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/application-setup.mdx
Clones the Aserto React and Node.js demo repository and installs all dependencies. This is an alternative to following the setup steps manually.
```shell
git clone git@github.com:aserto-demo/aserto-react-and-node-with-conditional-rendering.git
cd aserto-react-and-node-with-conditional-rendering
yarn install:all
```
--------------------------------
### Aserto Rails Configuration Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/ruby/rails.mdx
Provides a complete example of configuring the Aserto gem in a Rails application, including essential policy details and optional settings.
```ruby
# config/initializers/aserto.rb
require "aserto/rails"
Aserto.configure do |config|
config.enabled = true
config.policy_id = "my-policy-id"
config.tenant_id = "my-tenant-id"
config.authorizer_api_key = Rails.application.credentials.aserto[:authorizer_api_key]
config.policy_root = "peoplefinder"
config.service_url = "authorizer.prod.aserto.com:8443"
config.decision = "allowed"
config.logger = Rails.logger
config.identity_mapping = {
type: :sub,
from: :sub
}
end
```
--------------------------------
### Install via Go Get
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/command-line-interface/aserto-idp-cli/installation.mdx
Installs the aserto-idp using the Go programming language's get command. Note that this method installs the development version.
```go
# NOTE: The dev version will be in effect!
go get -u github.com/aserto-dev/aserto-idp
```
--------------------------------
### Install Dependencies
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/service-setup.mdx
Installs necessary Node.js packages for the Express.js service, including Express, JWT handling, CORS, and Aserto integration.
```bash
yarn init -y
yarn add express express-jwt jwks-rsa cors @aserto/aserto-node dotenv
```
--------------------------------
### Initializing Directory Client
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Provides an example of initializing the DirectoryServiceV3 client with essential configuration parameters like URL and CA file path.
```typescript
import { DirectoryServiceV3 } from "@aserto/aserto-node";
const directoryClient = DirectoryServiceV3({
url: 'localhost:9292',
caFile: `${process.env.HOME}/.local/share/topaz/certs/grpc-ca.crt`
});
```
--------------------------------
### Aserto Directory Client - Set Object Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example of how to create or update an object instance in the Aserto directory.
```typescript
const user = await directoryClient.setObject(
{
object: {
type: "user",
id: "test-object",
properties: {
displayName: "test object"
}
}
}
);
```
--------------------------------
### Set Object Instance
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/ruby/directory.mdx
Provides examples for creating a new object instance or updating an existing one in the Aserto directory. It covers both initial creation and modification of object properties.
```ruby
user = directory_client.set_object(object: { type: "user", key: "test-object", display_name: "test object" })
identity = directory_client.set_object(object: { type: "identity", key: "test-identity" })
# Update an existing object
user = directory_client.set_object(object: { type: "user", key: "test-object", display_name: "test object" })
user.display_name = 'test object edit'
updated_user = directory_client.set_object(object: user)
```
--------------------------------
### Add OIDC Dependencies
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/application-setup.mdx
Installs the `oidc-react` library, which is necessary for handling OpenID Connect authentication in the React application.
```shell
yarn add oidc-react@1.5.1
```
--------------------------------
### Downgrade to React 17
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/application-setup.mdx
Installs specific versions of React and related testing libraries to ensure compatibility with OIDC dependencies, which may not work with React 18.
```shell
yarn add react@17 react-dom@17 @testing-library/react@12 @types/react@17 @types/react-dom@17
```
--------------------------------
### Aserto Directory Client - Get Manifest Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example of retrieving the directory manifest.
```typescript
await directoryClient.getManifest();
```
--------------------------------
### Rego Policy Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/dotnet/dotnetcore.mdx
Example Rego policy that allows access to /profile on GET only to users with verified identities. Other endpoints allow anonymous access.
```rego
package MVC
default allow = false
# Allow access to /profile on GET only to users that have their identities verified.
allow = true {
input.request.method == "GET"
input.request.path == "/profile"
caller := input.user
caller.identities[i].verified == true
}
```
```rego
package MVC
# Allow anonymous access to all other endpoints.
allowed = true
```
--------------------------------
### Download Backend Instructions (Node.JS)
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/gdrive/install-the-backend.mdx
Provides instructions for downloading and installing the Google Drive backend for Node.JS. This includes steps to get the backend running after selection.
```Node.JS
Follow the directions to install dependencies and start the server.
```
--------------------------------
### Aserto Directory Client - Delete Manifest Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example of deleting the directory manifest.
```typescript
await directoryClient.deleteManifest();
```
--------------------------------
### Node.js Backend Download and Install Instructions
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/github/install-the-backend.mdx
Provides instructions for downloading and installing the Node.js backend. This includes steps to install dependencies and start the server, enabling interaction with Citadel resources via an API protected by an Aserto policy.
```Node.js
Follow the directions to install dependencies and start the server.
```
--------------------------------
### Aserto Directory Client - Check Permission Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example of checking if a user has a specific permission on an object.
```typescript
const check = await directoryClient.checkPermission({
subjectId: 'euang@acmecorp.com',
subjectType: 'user',
permission: 'read',
objectType: 'group',
objectId: 'admin',
});
```
--------------------------------
### Aserto Directory Client - Check Relation Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example of checking if a specific relation exists between a subject and an object.
```typescript
const check = directoryClient.checkRelation({
subjectId: 'euang@acmecorp.com',
subjectType: 'user',
name: 'identifier',
objectType: 'identity',
objectId: 'euang@acmecorp.com',
});
```
--------------------------------
### API Authorization Tutorial Video
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/api-auth/overview.mdx
This snippet embeds a YouTube video tutorial demonstrating the API Authorization Quickstart. It covers setting up a data-centric authorization model using ReBAC.
```html
```
--------------------------------
### Create React App
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/application-setup.mdx
Generates a new React application using Create React App with the 'react-app' generator.
```shell
yarn create react-app aserto-react-demo
cd aserto-react-demo
yarn start
```
--------------------------------
### Aserto Directory Client - Set Manifest Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example of setting or updating the directory manifest with a YAML configuration.
```typescript
await directoryClient.setManifest(`
# yaml-language-server: $schema=https://www.topaz.sh/schema/manifest.json
---
### model ###
model:
version: 3
### object type definitions ###
types:
### display_name: User ###
user:
relations:
### display_name: user#manager ###
manager: user
### display_name: Identity ###
identity:
relations:
### display_name: identity#identifier ###
identifier: user
### display_name: Group ###
group:
relations:
### display_name: group#member ###
member: user
permissions:
read: member
`);
```
--------------------------------
### Aserto Directory Client - Delete Object Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example showing how to delete an object instance from the Aserto directory.
```typescript
await directoryClient.deleteObject({ objectType: 'user', objectId: 'euang@acmecorp.com' });
```
--------------------------------
### Aserto Directory Client - Delete Relation Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example demonstrating how to delete a specific relation between objects in the Aserto directory.
```typescript
await directoryClient.deleteRelation({
subjectType: 'subjectType',
subjectId: 'subjectId',
relation: 'relationName',
objectType: 'objectType',
objectId: 'objectId',
});
```
--------------------------------
### Install Aserto Clients using Package Manager
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/dotnet/clients.mdx
Installs the Aserto.Clients NuGet package using the Package Manager console in Visual Studio.
```powershell
Install-Package Aserto.Clients
```
--------------------------------
### Install go-aserto SDK
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/go/install.mdx
Installs the go-aserto SDK using the go get command. This command fetches and installs the latest version of the package into your Go environment.
```sh
go get -u github.com/aserto-dev/go-aserto
```
--------------------------------
### Aserto Directory Client - Set Relation Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example demonstrating how to create or update a relation between two objects in the Aserto directory.
```typescript
const relation = await directoryClient.setRelation({
subjectId: 'subjectId',
subjectType: 'subjectType',
relation: 'relationName',
objectType: 'objectType',
objectId: 'objectId',
});
```
--------------------------------
### Install Aserto Clients using .NET CLI
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/dotnet/clients.mdx
Installs the Aserto.Clients NuGet package using the .NET Command Line Interface.
```cmd
dotnet add package Aserto.Clients
```
--------------------------------
### Aserto Directory Client - Relation Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example demonstrating how to retrieve relations for a given identity and then fetch the associated user object.
```typescript
const identity = 'euang@acmecorp.com';
const relation = await directoryClient.relation(
{
subjectType: 'user',
objectType: 'identity',
objectId: identity,
relation: 'identifier',
subjectId: 'euang@acmecorp.com'
}
);
if (!relation) {
throw new Error(`No relations found for identity ${identity}`)
};
const user = await directoryClient.object(
{ objectId: relation.subjectId, objectType: relation.subjectType }
);
```
--------------------------------
### Create AsertoClient Instance
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/spa.mdx
Demonstrates how to create an instance of the AsertoClient for use in a single-page application. It shows initialization with an access token and optional service URL and endpoint configuration, and also how to instantiate the client directly.
```javascript
import createAsertoClient from '@aserto/aserto-spa-js'
const aserto = await createAsertoClient({
accessToken: accessToken, // valid access token
serviceUrl: 'https://service-url', // defaults to window.location.origin
endpoint: '/__displaystatemap', // access map endpoint, defaults to /__displaystatemap
})
// or you can just instantiate the client on its own
import { AsertoClient } from '@aserto/aserto-spa-js'
const aserto = new AsertoClient({
accessToken: accessToken,
serviceUrl: 'https://service-url', // defaults to window.location.origin
endpoint: '/__displaystatemap', // access map endpoint, defaults to /__displaystatemap
})
// explicitly load
await aserto.reload()
```
--------------------------------
### Initialize Express Service and Dependencies
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/service-setup.mdx
Initializes the Express application and requires necessary Node.js modules for the service.
```javascript
require('dotenv').config()
const express = require('express')
const jwt = require('express-jwt')
const jwksRsa = require('jwks-rsa')
const cors = require('cors')
const app = express()
```
--------------------------------
### Resource Mapper Type Definition and Examples
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Defines the `ResourceMapper` type and provides examples of both a custom function mapping and a plain resource context.
```ts
// provides a custom resource context,
type ResourceMapper =
| ResourceContext
| ((req?: Request) => Promise);
// examples
async (req: Request) => { return { customKey: req.params.id } };
// or just a plain resource context
{ customKey: "customValue" }
```
--------------------------------
### Custom Identity Provider Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/python/flask.mdx
Provides an example of a custom identity provider function that extracts user identity from Flask's `g` object.
```python
from flask import g
from aserto.api.v1.identity_pb2 import Identity, IdentityType
def identity_provider() -> Identity:
identity = g.identity
if identity is None:
return Identity(IdentityType.IDENTITY_TYPE_NONE)
return Identity(type=IdentityType.IDENTITY_TYPE_SUB, value=identity)
```
--------------------------------
### Protected API Endpoint Setup
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/service-setup.mdx
Sets up CORS, defines a protected API endpoint that uses the JWT validation middleware, and starts the Express server.
```javascript
// Enable CORS
app.use(cors())
// Protected API endpoint
app.get('/api/protected', checkJwt, function (req, res) {
//send the response
res.json({
secretMessage: 'Here you go, very sensitive information for ya!',
})
})
// Launch the API Server at localhost:8080
app.listen(8080)
```
--------------------------------
### Download Slack Backend Instructions (Node.JS)
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/slack/install-the-backend.mdx
Instructions for downloading and installing the Slack backend for Node.js. This backend provides an API protected by an Aserto policy.
```Node.JS
Follow the instructions to install dependencies and start the server.
```
--------------------------------
### Run application and server in parallel
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/update-the-application.mdx
Executes the `start:all` script, which uses `npm-run-all` to launch both the application and the API server concurrently. This command is used after configuring the necessary scripts in `package.json`.
```bash
yarn start:all
```
--------------------------------
### Custom Resource Context Provider Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/python/flask.mdx
Provides an example of a custom resource context provider function that extracts request view arguments as the resource context.
```python
from flask import request
def resource_context_from_request() -> ResourceContext:
return request.view_args or {}
```
--------------------------------
### Create AuthorizerClient Instance
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/python/api-client.mdx
Shows how to instantiate the AuthorizerClient with necessary identity and options, including API key, tenant ID, and optional configuration for local authorizers.
```python
from aserto import Identity, IdentityType
from aserto.client.authorizer import AuthorizerClient, AuthorizerOptions
client = AuthorizerClient(
identity=Identity(IdentityType.IDENTITY_TYPE_NONE),
options=AuthorizerOptions(
api_key=YOUR_ASERTO_API_KEY,
tenant_id=YOUR_ASERTO_TENANT_ID,
),
)
```
--------------------------------
### Configure Environment Variables for OIDC
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/application-setup.mdx
Sets up the `.env` file with necessary environment variables to configure the application to use Aserto's demo Identity Provider (IDP).
```shell
REACT_APP_OIDC_DOMAIN=acmecorp.demo.aserto.com
REACT_APP_OIDC_CLIENT_ID=acmecorp-app
REACT_APP_OIDC_AUDIENCE=acmecorp-app
REACT_APP_API_ORIGIN=http://localhost:8080
```
--------------------------------
### Add Stylesheet
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/application-setup.mdx
References an external stylesheet for the application's UI. This should be placed within the `` section of your `index.html` file.
```html
```
--------------------------------
### Display State Map Middleware Setup
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Demonstrates how to use the `displayStateMap` middleware from the `@aserto/aserto-node` library to set up an endpoint that returns the display state map. Includes a basic example with required options.
```javascript
const { displayStateMap } = require('@aserto/aserto-node');
const options = {
authorizerServiceUrl: 'localhost:8282', // required - must pass a valid host:port
policyRoot: 'policy' // required - must be a string representing the policy root (the first component of the policy module name)
};
app.use(displayStateMap(options));
```
--------------------------------
### Aserto Policy for Profile GET Request
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/dotnet/dotnetcore.mdx
A Rego policy file that defines the authorization rules for the GET request to the /profile endpoint. It specifies that by default, access is not allowed.
```rego
package quickstartmvc.GET.home.profile
default allowed = false
allowed {
// Policy rules go here
}
```
--------------------------------
### Initialize Python Directory Client
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/python/directory.mdx
Demonstrates how to initialize the Aserto Python Directory Client with various configuration options like API key, tenant ID, and service addresses.
```python
from aserto.client.directory.v3 import Directory
ds = Directory(api_key="my_api_key", tenant_id="1234", address="localhost:9292")
```
--------------------------------
### Getting a Relation Instance
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Illustrates how to fetch a relation instance between a subject and an object, specifying their types, IDs, and the relation name.
```typescript
relation({
subjectType: 'subject-type',
subjectId: 'subject-id',
relation: 'relation-name',
objectType: 'object-type',
objectId: 'object-id',
})
const identity = 'euang@acmecorp.com';
const relation = await directoryClient.relation({
subjectType: 'user',
subjectId: 'euang@acmecorp.com',
relation: 'identifier',
objectType: 'identity'
objectId: identity
});
```
--------------------------------
### Initialize Aserto Directory Client
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/ruby/directory.mdx
Demonstrates how to initialize the Aserto Directory Client in Ruby, specifying the URL, tenant ID, and API key for connecting to the Aserto directory service. It also mentions optional parameters like `cert_path` for local connections.
```ruby
require 'aserto/directory/client'
directory_client = Aserto::Directory::Client.new(
url: "directory.prod.aserto.com:8443",
tenant_id: "aserto-tenant-id",
api_key: "basic directory api key",
)
```
--------------------------------
### List Policy Templates
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/command-line-interface/policy-cli/init.mdx
Lists available policy templates that can be used to bootstrap new policies. This command fetches and displays a table of template names, kinds, and descriptions.
```bash
policy templates list
Fetching templates .
NAME KIND DESCRIPTION
github cicd GitHub policy CI/CD template.
gitlab cicd GitLab policy CI/CD template.
policy-template policy Minimal policy template.
```
--------------------------------
### Aserto SDK - Is Method Usage
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/javascript/express.mdx
Example of calling the `Is` method to perform an authorization check. Requires identity, policy, and resource context.
```ts
// Is
await authClient
.Is({
identityContext: identityContext(
"morty@the-citadel.com",
"SUB"
),
policyInstance: policyInstance("todo", "todo"),
policyContext: policyContext("todoApp.POST.todos", ["allowed"]),
resourceContext: {
ownerID: "fd1614d3-c39a-4781-b7bd-8b96f5a5100d",
},
})
```
--------------------------------
### Install via Homebrew
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/command-line-interface/aserto-idp-cli/installation.mdx
Installs the aserto-idp using Homebrew on macOS or LinuxBrew for Linux systems. This command taps the Aserto repository and then installs the package.
```shell
brew tap aserto-dev/tap && brew install aserto-idp
```
--------------------------------
### Get Multiple Objects
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/python/directory.mdx
Demonstrates how to retrieve multiple directory objects in a single request using their type and ID.
```python
from aserto.client.directory.v3 import ObjectIdentifier
objects = ds.get_object_many([
ObjectIdentifier(type="user", id="euan@acmecorp.com"),
ObjectIdentifier(type="group", id="marketing"),
])
```
--------------------------------
### User JSON Object Example
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/quickstarts/react/adding-users.mdx
An example of a user's JSON object as stored in the Aserto Directory, showcasing properties like display name, email, and roles.
```json
{
"displayName": "Euan Garden",
"email": "euang@acmecorp.com",
...
"properties": {
"department": "Sales Engagement Management",
"manager": "2bfaa552-d9a5-41e9-a6c3-5be62b4433c8",
"phone": "+1-804-555-3383",
"title": "Salesperson"
"roles": [
"acmecorp",
"sales-engagement-management",
"user",
"viewer"
],
...
},
...
}
```
--------------------------------
### Get Object with Relations
Source: https://github.com/aserto-dev/aserto-docs/blob/main/docs/software-development-kits/python/directory.mdx
Shows how to retrieve a directory object, optionally including its relations, and how to paginate through relations if there are many.
```python
# without relations:
user = ds.get_object(object_type="user", object_id="euang@acmecorp.com")
# with relations:
from aserto.client.directory.v3 import PaginationRequest
page = PaginationRequest(size=10)
while True:
resp = ds.get_object(object_type="user", object_id="euang@acmecorp.com", with_relations=True, page=page)
user = resp.result # The returned object.
relations_page = resp.relations # A page of relations.
if not resp.page.next_token:
# we've reached the last page.
break
# request the next page.
page.token = resp.page.next_token
```