Skip to content

Commit

Permalink
Merge pull request #21 from OldSneerJaw/heroku-auth-identity
Browse files Browse the repository at this point in the history
Require identity scope for Heroku authorizations
  • Loading branch information
OldSneerJaw authored Oct 30, 2021
2 parents 8d23686 + 02b67d3 commit cde6120
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 27 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/). All notable changes will be documented in this file.

## [Unreleased](https://github.com/OldSneerJaw/borealis-pg-cli/compare/v0.4.0...HEAD)
- Require "identity" scope for Heroku authorizations

## [0.4.0](https://github.com/OldSneerJaw/borealis-pg-cli/compare/v0.3.1...v0.4.0)
- Clarified in the `borealis-pg:tunnel` command's output that it does not accept keyboard input
- Handle port conflicts for secure tunnels on Windows
Expand Down
2 changes: 1 addition & 1 deletion src/commands/borealis-pg/extensions/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const baseTestContext = test.stdout()
.post('/oauth/authorizations', {
description: 'Borealis PG CLI plugin temporary auth token',
expires_in: 180,
scope: ['read'],
scope: ['read', 'identity'],
})
.reply(201, {id: fakeHerokuAuthId, access_token: {token: fakeHerokuAuthToken}})
.delete(`/oauth/authorizations/${fakeHerokuAuthId}`)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/borealis-pg/extensions/install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const baseTestContext = test.stdout()
.post('/oauth/authorizations', {
description: 'Borealis PG CLI plugin temporary auth token',
expires_in: 180,
scope: ['read'],
scope: ['read', 'identity'],
})
.reply(201, {id: fakeHerokuAuthId, access_token: {token: fakeHerokuAuthToken}})
.delete(`/oauth/authorizations/${fakeHerokuAuthId}`)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/borealis-pg/extensions/remove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const baseTestContext = test.stdout()
api => api.post('/oauth/authorizations', {
description: 'Borealis PG CLI plugin temporary auth token',
expires_in: 180,
scope: ['read'],
scope: ['read', 'identity'],
})
.reply(201, {id: fakeHerokuAuthId, access_token: {token: fakeHerokuAuthToken}})
.delete(`/oauth/authorizations/${fakeHerokuAuthId}`)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/borealis-pg/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ an add-on Postgres database.`
usePersonalUser: boolean,
enableWriteAccess: boolean,
showSpinner: boolean): Promise<[SshConnectionInfo, DbConnectionInfo]> {
const authorization = await createHerokuAuth(this.heroku, true)
const authorization = await createHerokuAuth(this.heroku)
try {
const dbConnInfoPromise =
!usePersonalUser ?
Expand Down
2 changes: 1 addition & 1 deletion src/commands/borealis-pg/tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ add-on Postgres database.`
private async createPersonalUsers(
addonName: string,
enableWriteAccess: boolean): Promise<[SshConnectionInfo, DbConnectionInfo]> {
const authorization = await createHerokuAuth(this.heroku, true)
const authorization = await createHerokuAuth(this.heroku)
const accessLevelName = enableWriteAccess ? 'read/write' : 'read-only'
try {
const [sshConnInfoResult, dbConnInfoResult] = await applyActionSpinner(
Expand Down
18 changes: 1 addition & 17 deletions src/heroku-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,11 @@ describe('createHerokuAuth', () => {
mockHerokuApiClientInstance = instance(mockHerokuApiClientType)
})

it('requests an authorization without the "identity" scope by default', async () => {
it('requests a Heroku authorization', async () => {
const result = await createHerokuAuth(mockHerokuApiClientInstance)

expect(result).to.equal(fakeAuthorization)

verify(mockHerokuApiClientType.post<OAuthAuthorization>(
'/oauth/authorizations',
deepEqual({
body: {
description: 'Borealis PG CLI plugin temporary auth token',
expires_in: 180,
scope: ['read'],
},
}))).once()
})

it('requests an authorization with the "identity" scope', async () => {
const result = await createHerokuAuth(mockHerokuApiClientInstance, true)

expect(result).to.equal(fakeAuthorization)

verify(mockHerokuApiClientType.post<OAuthAuthorization>(
'/oauth/authorizations',
deepEqual({
Expand Down
7 changes: 2 additions & 5 deletions src/heroku-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import {HTTPError} from 'http-call'
* @param herokuApiClient The Heroku API client
* @param includeIdentityScope Whether the authorization should include the "identity" scope
*/
export async function createHerokuAuth(
herokuApiClient: APIClient,
includeIdentityScope = false): Promise<OAuthAuthorization> {
const scopes = includeIdentityScope ? ['read', 'identity'] : ['read']
export async function createHerokuAuth(herokuApiClient: APIClient): Promise<OAuthAuthorization> {
const response = await herokuApiClient.post<OAuthAuthorization>(
'/oauth/authorizations',
{
body: {
description: 'Borealis PG CLI plugin temporary auth token',
expires_in: 180,
scope: scopes,
scope: ['read', 'identity'],
},
})

Expand Down

0 comments on commit cde6120

Please sign in to comment.