Skip to content

Commit

Permalink
feat(3114): update for auth and resource server.
Browse files Browse the repository at this point in the history
  • Loading branch information
koekiebox committed Dec 11, 2024
1 parent a9f0fff commit 7d562b5
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ export const CONFIG: Config = {
testnetAutoPeerUrl: process.env.TESTNET_AUTOPEER_URL ?? '',
authServerDomain: process.env.AUTH_SERVER_DOMAIN || 'http://localhost:3006',
graphqlUrl: process.env.GRAPHQL_URL,
idpSecret: process.env.IDP_SECRET
idpSecret: process.env.IDP_SECRET,
operatorTenantId:
process.env.OPERATOR_TENANT_ID || '438fa74a-fa7d-4317-9ced-dde32ece1787'
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
exports.up = function (knex) {
return Promise.all([
knex.schema.alterTable('walletAddresses', function (table) {
table.uuid('tenantId')
table.foreign(['tenantId']).references('tenants.id')
table.index(['tenantId'])
table.uuid('tenantId').index().notNullable()
//table.foreign(['tenantId']).references('tenants.id')
})
])
}
Expand Down
12 changes: 8 additions & 4 deletions packages/backend/src/open_payments/wallet_address/routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ describe('Wallet Address Routes', (): void => {
addPropNotVisibleInOpenPayments.fieldValue = 'it-is-not'
addPropNotVisibleInOpenPayments.visibleInOpenPayments = false
const walletAddress = await createWalletAddress(deps, {
tenantId: config.operatorTenantId,
publicName: faker.person.firstName(),
additionalProperties: [addProp, addPropNotVisibleInOpenPayments]
})
Expand All @@ -118,8 +119,9 @@ describe('Wallet Address Routes', (): void => {
publicName: walletAddress.publicName,
assetCode: walletAddress.asset.code,
assetScale: walletAddress.asset.scale,
authServer: config.authServerGrantUrl,
resourceServer: config.openPaymentsUrl,
// Ensure the tenant id is returned for auth and resource server:
authServer: `${config.authServerGrantUrl}/${config.operatorTenantId}`,
resourceServer: `${config.openPaymentsUrl}/${config.operatorTenantId}`,
additionalProperties: {
[addProp.fieldKey]: addProp.fieldValue
}
Expand All @@ -145,6 +147,7 @@ describe('Wallet Address Routes', (): void => {

test('returns wallet address', async (): Promise<void> => {
const walletAddress = await createWalletAddress(deps, {
tenantId: config.operatorTenantId,
publicName: faker.person.firstName()
})

Expand All @@ -160,8 +163,9 @@ describe('Wallet Address Routes', (): void => {
publicName: walletAddress.publicName,
assetCode: walletAddress.asset.code,
assetScale: walletAddress.asset.scale,
authServer: config.authServerGrantUrl,
resourceServer: config.openPaymentsUrl
// Ensure the tenant id is returned for auth and resource server:
authServer: `${config.authServerGrantUrl}/${config.operatorTenantId}`,
resourceServer: `${config.openPaymentsUrl}/${config.operatorTenantId}`,
})
})
})
Expand Down
9 changes: 7 additions & 2 deletions packages/backend/src/open_payments/wallet_address/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ export async function getWalletAddress(
)

ctx.body = walletAddress.toOpenPaymentsType({
authServer: deps.config.authServerGrantUrl,
resourceServer: deps.config.openPaymentsUrl
authServer: `${ensureTrailingSlash(deps.config.authServerGrantUrl)}${walletAddress.tenantId}`,
resourceServer: `${ensureTrailingSlash(deps.config.openPaymentsUrl)}${walletAddress.tenantId}`
})
}

function ensureTrailingSlash(str: string): string {
if (!str.endsWith('/')) return `${str}/`
return str
}

interface ListSubresourceOptions<M extends WalletAddressSubresource> {
ctx: ListContext
getWalletAddressPage: WalletAddressSubresourceService<M>['getWalletAddressPage']
Expand Down
2 changes: 1 addition & 1 deletion packages/mock-account-service-lib/src/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export async function setupFromSeed(
logger.debug('hostname: ', config.publicHost)

const url = `${config.publicHost}/${account.path}`
const tenantId = '438fa74a-fa7d-4317-9ced-dde32ece1787' //TODO @jason complete this: <-
const tenantId = config.operatorTenantId
let walletAddress = await getWalletAddressByURL(url)
if (!walletAddress) {
walletAddress = await createWalletAddress(
Expand Down
1 change: 1 addition & 0 deletions packages/mock-account-service-lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface Config {
authServerDomain: string
graphqlUrl: string
idpSecret: string
operatorTenantId: string
}
export interface Webhook {
id: string
Expand Down

0 comments on commit 7d562b5

Please sign in to comment.