Skip to content

Commit

Permalink
feat: new auth server introspection behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
njlie committed Jul 24, 2024
1 parent b7c909e commit d030e41
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/auth/src/access/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function compareRequestAndGrantAccessItems(
) {
return false
} else if (
restOfRequestAccessItem[key as keyof typeof restOfRequestAccessItem] !==
requestAccessItemValue !==
restOfgrantAccessItem[key as keyof typeof restOfgrantAccessItem]
) {
return false
Expand Down
8 changes: 3 additions & 5 deletions packages/auth/src/accessToken/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ async function introspectToken(
'introspected access token'
)

ctx.body = grantToTokenInfo(tokenInfo?.grant, tokenInfo?.accessItem)
ctx.body = grantToTokenInfo(tokenInfo?.grant, tokenInfo?.access)
}

function grantToTokenInfo(grant?: Grant, accessItem?: Access): TokenInfo {
function grantToTokenInfo(grant?: Grant, access?: Access[]): TokenInfo {
if (!grant) {
return {
active: false
Expand All @@ -117,9 +117,7 @@ function grantToTokenInfo(grant?: Grant, accessItem?: Access): TokenInfo {
return {
active: true,
grant: grant.id,
access: accessItem
? [toOpenPaymentsAccess(accessItem)]
: grant.access.map(toOpenPaymentsAccess),
access: access?.map(toOpenPaymentsAccess) ?? [],
client: grant.client
}
}
Expand Down
9 changes: 5 additions & 4 deletions packages/auth/src/accessToken/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface AccessTokenService {
introspect(
tokenValue: string,
access?: AccessItem[]
): Promise<{ grant: Grant; accessItem?: Access } | undefined>
): Promise<{ grant: Grant, access: Access[] } | undefined>
create(grantId: string, trx?: TransactionOrKnex): Promise<AccessToken>
revoke(id: string, trx?: TransactionOrKnex): Promise<AccessToken | undefined>
revokeByGrantId(grantId: string, trx?: TransactionOrKnex): Promise<number>
Expand Down Expand Up @@ -77,12 +77,13 @@ async function introspect(
deps: ServiceDependencies,
tokenValue: string,
access?: AccessItem[]
): Promise<{ grant: Grant; accessItem?: Access } | undefined> {
): Promise<{ grant: Grant, access: Access[] } | undefined> {
const token = await AccessToken.query(deps.knex)
.findOne({ value: tokenValue })
.withGraphFetched('grant.access')

let foundAccessItem: Access | undefined
const foundAccess: Access[] = []
if (!token) return
if (isTokenExpired(token)) {
return undefined
Expand All @@ -102,12 +103,12 @@ async function introspect(
if (!foundAccessItem) {
return undefined
} else {
return { grant: token.grant, accessItem: foundAccessItem }
foundAccess.push(foundAccessItem)
}
}
}

return { grant: token.grant }
return { grant: token.grant, access: foundAccess }
}
}

Expand Down

0 comments on commit d030e41

Please sign in to comment.