Skip to content

Commit

Permalink
fix: change interaction to use the correct auth domain
Browse files Browse the repository at this point in the history
  • Loading branch information
dragosp1011 committed Oct 19, 2023
1 parent 47705b0 commit 8730ea1
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 41 deletions.
36 changes: 28 additions & 8 deletions localenv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ pnpm localenv:compose:psql up
pnpm localenv:compose:psql down --volumes
```

The local environment consists of a primary Rafiki instance and a secondary Rafiki instance, each with
its own docker compose files ([Cloud Nine Wallet](./cloud-nine-wallet/docker-compose.yml), [Happy Life Bank](./happy-life-bank/docker-compose.yml)).
The primary Cloud Nine Wallet docker compose file (`./cloud-nine-wallet/docker-compose.yml`) includes the main Rafiki services `backend` and `auth`, as well
as the required data stores tigerbeetle (if enabled), redis, and postgres, so it can be run on its own. Furthermore,
both include the `local-signature-utils` signature generation app for Postman.
The secondary Happy Life Bank docker compose file (`./happy-life-bank/docker-compose.yml`) includes only the Rafiki services, not the data stores. It uses the
data stores created by the primary Rafiki instance so it can't be run by itself.
The `pnpm localenv:compose up` command starts both the primary instance and the secondary.

#### Autopeering

If you want to start the local env and peer it automatically to rafiki.money, you can run the following commands:

```
Expand All @@ -109,14 +120,23 @@ pnpm localenv:autopeer:start
pnpm localenv:autopeer:start:psql
```

The local environment consists of a primary Rafiki instance and a secondary Rafiki instance, each with
its own docker compose files ([Cloud Nine Wallet](./cloud-nine-wallet/docker-compose.yml), [Happy Life Bank](./happy-life-bank/docker-compose.yml)).
The primary Cloud Nine Wallet docker compose file (`./cloud-nine-wallet/docker-compose.yml`) includes the main Rafiki services `backend` and `auth`, as well
as the required data stores tigerbeetle (if enabled), redis, and postgres, so it can be run on its own. Furthermore,
both include the `local-signature-utils` signature generation app for Postman.
The secondary Happy Life Bank docker compose file (`./happy-life-bank/docker-compose.yml`) includes only the Rafiki services, not the data stores. It uses the
data stores created by the primary Rafiki instance so it can't be run by itself.
The `pnpm localenv:compose up` command starts both the primary instance and the secondary.
Your local cloud nine rafiki instance will be peered automatically in this case with https://rafiki.money instance.
The required services will be exposed externally using [ngrok](https://www.npmjs.com/package/ngrok) and [tunnelmole](https://www.npmjs.com/package/tunnelmole) packages.
Ngrok is used to expose open-payments api and auth api. These apis require a https protocol for correctly validating the requests signatures and ngrok will add X-Forwarded-Proto to secure requests that helps koa to identify requests as secure.
Tunnelmole package is used for exposing externally ilp connector.

There is no need for ngrok token in case you are planning to try out only the API requests.
In case you are looking to test the open payments example with the interaction flow, then the ngrok token should be provided in `~/cloud-nine-wallet/.env` file
as `NGROK_TOKEN={YOUR TOKEN}`. Ngrok does not serve html without providing the auth token.

To use the postman collection examples - copy the created payment pointer and set it into `senderPaymentPointer` postman variable in `Remote Environment`.

After stopping the script it is necessary to clear the environment using the command described in setup. This is necessary as on a new run of the scripts (with autopeeing or not) the payment pointer url will differ.

```
// tear down and remove volumes
pnpm localenv:compose down --volumes
```

### Shutting down

Expand Down
17 changes: 9 additions & 8 deletions localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: c9
services:
cloud-nine-mock-ase:
hostname: cloud-nine-wallet
image: rafiki-mock-ase
image: rafiki-mock-ase-10
build:
context: ../..
dockerfile: ./localenv/mock-account-servicing-entity/Dockerfile
Expand All @@ -17,7 +17,8 @@ services:
PORT: 80
SEED_FILE_LOCATION: /workspace/seed.yml
KEY_FILE: /workspace/private-key.pem
PUBLIC_HOST: ${CLOUD_NINE_PUBLIC_HOST:-'https://cloud-nine-wallet-backend'}
PUBLIC_HOST: ${CLOUD_NINE_PUBLIC_HOST:-https://cloud-nine-wallet-backend}
AUTH_SERVER_DOMAIN: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-http://localhost:3006}
TESTNET_AUTOPEER_URL: ${TESTNET_AUTOPEER_URL}
volumes:
- ../cloud-nine-wallet/seed.yml:/workspace/seed.yml
Expand Down Expand Up @@ -49,16 +50,16 @@ services:
USE_TIGERBEETLE: ${USE_TIGERBEETLE-false}
TIGERBEETLE_CLUSTER_ID: ${TIGERBEETLE_CLUSTER_ID-0}
TIGERBEETLE_REPLICA_ADDRESSES: ${TIGERBEETLE_REPLICA_ADDRESSES-''}
AUTH_SERVER_GRANT_URL: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-'http://cloud-nine-wallet-auth:3006'}
AUTH_SERVER_GRANT_URL: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-http://cloud-nine-wallet-auth:3006}
AUTH_SERVER_INTROSPECTION_URL: http://cloud-nine-wallet-auth:3007
ILP_ADDRESS: ${ILP_ADDRESS:-'test.cloud-nine-wallet'}
ILP_ADDRESS: ${ILP_ADDRESS:-test.cloud-nine-wallet}
STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
PUBLIC_HOST: ${CLOUD_NINE_PUBLIC_HOST:-'http://cloud-nine-wallet-backend'}
OPEN_PAYMENTS_URL: ${CLOUD_NINE_OPEN_PAYMENTS_URL:-'http://cloud-nine-wallet-backend'}
PUBLIC_HOST: ${CLOUD_NINE_PUBLIC_HOST:-http://cloud-nine-wallet-backend}
OPEN_PAYMENTS_URL: ${CLOUD_NINE_OPEN_PAYMENTS_URL:-http://cloud-nine-wallet-backend}
WEBHOOK_URL: http://cloud-nine-wallet/webhooks
EXCHANGE_RATES_URL: http://cloud-nine-wallet/rates
REDIS_URL: redis://shared-redis:6379/0
PAYMENT_POINTER_URL: ${CLOUD_NINE_PAYMENT_POINTER_URL:-'https://cloud-nine-wallet-backend/.well-known/pay'}
PAYMENT_POINTER_URL: ${CLOUD_NINE_PAYMENT_POINTER_URL:-https://cloud-nine-wallet-backend/.well-known/pay}
ILP_CONNECTOR_ADDRESS: ${CLOUD_NINE_CONNECTOR_URL}
depends_on:
- shared-database
Expand All @@ -79,7 +80,7 @@ services:
NODE_ENV: ${NODE_ENV:-development}
TRUST_PROXY: ${TRUST_PROXY}
AUTH_DATABASE_URL: postgresql://cloud_nine_wallet_auth:cloud_nine_wallet_auth@shared-database/cloud_nine_wallet_auth
AUTH_SERVER_DOMAIN: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-'http://localhost:3006'}
AUTH_SERVER_DOMAIN: ${CLOUD_NINE_AUTH_SERVER_DOMAIN:-http://localhost:3006}
depends_on:
- shared-database
shared-database:
Expand Down
12 changes: 6 additions & 6 deletions localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
PORT: 80
SEED_FILE_LOCATION: /workspace/seed.yml
KEY_FILE: /workspace/private-key.pem
PUBLIC_HOST: ${HAPPY_LIFE_BANK_PUBLIC_HOST:-'https://happy-life-bank-backend'}
PUBLIC_HOST: ${HAPPY_LIFE_BANK_PUBLIC_HOST:-https://happy-life-bank-backend}
volumes:
- ../happy-life-bank/seed.yml:/workspace/seed.yml
- ../happy-life-bank/private-key.pem:/workspace/private-key.pem
Expand Down Expand Up @@ -43,16 +43,16 @@ services:
USE_TIGERBEETLE: ${USE_TIGERBEETLE-false}
TIGERBEETLE_CLUSTER_ID: ${TIGERBEETLE_CLUSTER_ID-0}
TIGERBEETLE_REPLICA_ADDRESSES: ${TIGERBEETLE_REPLICA_ADDRESSES-''}
AUTH_SERVER_GRANT_URL: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-'http://happy-life-bank-auth:3006'}
AUTH_SERVER_GRANT_URL: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-http://happy-life-bank-auth:3006}
AUTH_SERVER_INTROSPECTION_URL: http://happy-life-bank-auth:3007
ILP_ADDRESS: test.happy-life-bank
STREAM_SECRET: BjPXtnd00G2mRQwP/8ZpwyZASOch5sUXT5o0iR5b5wU=
PUBLIC_HOST: ${HAPPY_LIFE_BANK_PUBLIC_HOST:-'http://happy-life-bank-backend'}
PUBLIC_HOST: ${HAPPY_LIFE_BANK_PUBLIC_HOST:-http://happy-life-bank-backend}
WEBHOOK_URL: http://happy-life-bank/webhooks
OPEN_PAYMENTS_URL: ${HAPPY_LIFE_BANK_OPEN_PAYMENTS_URL:-'http://happy-life-bank-backend'}
OPEN_PAYMENTS_URL: ${HAPPY_LIFE_BANK_OPEN_PAYMENTS_URL:-http://happy-life-bank-backend}
EXCHANGE_RATES_URL: http://happy-life-bank/rates
REDIS_URL: redis://shared-redis:6379/1
PAYMENT_POINTER_URL: ${HAPPY_LIFE_BANK_PAYMENT_POINTER_URL:-'https://happy-life-bank-backend/.well-known/pay'}
PAYMENT_POINTER_URL: ${HAPPY_LIFE_BANK_PAYMENT_POINTER_URL:-https://happy-life-bank-backend/.well-known/pay}
depends_on:
- cloud-nine-backend
happy-life-auth:
Expand All @@ -68,7 +68,7 @@ services:
environment:
NODE_ENV: development
AUTH_DATABASE_URL: postgresql://happy_life_bank_auth:happy_life_bank_auth@shared-database/happy_life_bank_auth
AUTH_SERVER_DOMAIN: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-'http://localhost:4006'}
AUTH_SERVER_DOMAIN: ${HAPPY_LIFE_BANK_AUTH_SERVER_DOMAIN:-http://localhost:4006}
depends_on:
- cloud-nine-auth
happy-life-admin:
Expand Down
5 changes: 3 additions & 2 deletions localenv/mock-account-servicing-entity/app/lib/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@ export class ApiClient {

public static async endInteraction(
interactId: string,
nonce: string
nonce: string,
authServerDomain: string
): Promise<ApiResponse> {
window.location.href = `http://localhost:3006/interact/${interactId}/${nonce}/finish`
window.location.href = `${authServerDomain}/interact/${interactId}/${nonce}/finish`
return {
isFailure: false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface Config {
key: crypto.KeyObject
publicHost: string
testnetAutoPeerUrl: string
authServerDomain: string
}

export const CONFIG: Config = {
Expand All @@ -66,5 +67,6 @@ export const CONFIG: Config = {
),
key: parseOrProvisionKey(process.env.KEY_FILE),
publicHost: process.env.PUBLIC_HOST ?? '',
testnetAutoPeerUrl: process.env.TESTNET_AUTOPEER_URL ?? ''
testnetAutoPeerUrl: process.env.TESTNET_AUTOPEER_URL ?? '',
authServerDomain: process.env.AUTH_SERVER_DOMAIN || 'http://localhost:3006'
}
10 changes: 8 additions & 2 deletions localenv/mock-account-servicing-entity/app/routes/shoe-shop.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { useLocation } from '@remix-run/react'
import { useLoaderData, useLocation } from '@remix-run/react'
import { useEffect, useState } from 'react'
import { ApiClient } from '~/lib/apiClient'
import { parseQueryString } from '~/lib/utils'
import { CONFIG as config } from '~/lib/parse_config.server'

export function loader() {
return config.authServerDomain
}

function AuthorizedView({
thirdPartyName,
Expand All @@ -16,6 +21,7 @@ function AuthorizedView({
interactId: string
nonce: string
}) {
const authServerDomain = useLoaderData<typeof loader>()
return (
<>
<div className='row'>
Expand All @@ -35,7 +41,7 @@ function AuthorizedView({
<button
className='btn btn-primary'
onClick={() => {
ApiClient.endInteraction(interactId, nonce)
ApiClient.endInteraction(interactId, nonce, authServerDomain)
}}
>
Continue
Expand Down
42 changes: 28 additions & 14 deletions scripts/localenv-tunnel-setup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
let tunnelmole

const fs = require('fs')
const ngrok = require('ngrok')
const dotenv = require('dotenv')
const { v4 } = require('uuid')

let tunnelmole
let envs

const envFile = './localenv/cloud-nine-wallet/.env'
function checkExistingEnvFile() {
if (fs.existsSync(envFile)) {
Expand All @@ -17,20 +18,29 @@ function checkExistingEnvFile() {
}

function getEnvs(opUrl, authUrl, connectorUrl) {
return Object.entries({
return {
// set to "testing" as in "development" - op client is replacing https with http
NODE_ENV: 'testing',
TRUST_PROXY: true,
TESTNET_AUTOPEER_URL: 'https://autopeer.rafiki.money',
TESTNET_AUTOPEER_URL:
process.env.TESTNET_AUTOPEER_URL ?? 'https://autopeer.rafiki.money',
ILP_ADDRESS: process.env.ILP_ADDRESS || `test.local-playground-${v4()}`,
CLOUD_NINE_PUBLIC_HOST: opUrl,
CLOUD_NINE_OPEN_PAYMENTS_URL: opUrl,
CLOUD_NINE_PAYMENT_POINTER_URL: `${opUrl}/.well-known/pay`,
CLOUD_NINE_AUTH_SERVER_DOMAIN: authUrl,
CLOUD_NINE_CONNECTOR_URL: connectorUrl
})
.map((entry) => entry.join('='))
.join('\n')
CLOUD_NINE_CONNECTOR_URL: connectorUrl,
NGROK_TOKEN: process.env.NGROK_TOKEN
}
}

async function writeEnvs(envs) {
await fs.writeFileSync(
'./localenv/cloud-nine-wallet/.env',
Object.entries(envs)
.map((entry) => entry.join('='))
.join('\n')
)
}

async function createTunnel(port) {
Expand All @@ -41,7 +51,8 @@ async function createTunnel(port) {
}

async function createNgrokTunnel(port) {
const tunnel = await ngrok.connect(port)
const authtoken = process.env.NGROK_TOKEN
const tunnel = await ngrok.connect({ port, authtoken })

console.log(`Created tunnel for port ${port}: ${tunnel}`)
return tunnel
Expand All @@ -61,18 +72,21 @@ async function connect() {

const connectorUrl = await createTunnel(3002)

await fs.writeFileSync(
'./localenv/cloud-nine-wallet/.env',
getEnvs(openPaymentsUrl, authUrl, connectorUrl)
)
envs = getEnvs(openPaymentsUrl, authUrl, connectorUrl)
await writeEnvs(envs)

console.log('Tunnels and .env file are ready!')
}

connect()

process.on('SIGINT', function () {
process.on('SIGINT', async function () {
console.log('Tunnels are closing...')

// clean the env variables as other urls will be generated at next run
await writeEnvs({
ILP_ADDRESS: envs.ILP_ADDRESS,
NGROK_TOKEN: envs.NGROK_TOKEN
})
process.exit()
})

0 comments on commit 8730ea1

Please sign in to comment.