Skip to content

Commit b758487

Browse files
committed
Merge branch 'develop' into add/org-view-table-sort
# Conflicts: # src/components/tables/table.js
2 parents c62fe1e + 99bd854 commit b758487

File tree

18 files changed

+108
-102
lines changed

18 files changed

+108
-102
lines changed

.env.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ NEXTAUTH_URL=http://127.0.0.1:3000
22
NEXTAUTH_SECRET=next-auth-cypress-secret
33
DATABASE_URL=postgres://postgres:postgres@localhost:5434/osm-teams-test
44
TESTING=true
5-
LOG_LEVEL=silent
5+
LOG_LEVEL=silent
6+
AUTH_URL=http://127.0.0.1:3000

app/index.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

next.config.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,14 @@ module.exports = {
1111
process.env.OSM_API ||
1212
process.env.OSM_DOMAIN ||
1313
'https://www.openstreetmap.org',
14-
OSM_HYDRA_ID: process.env.OSM_HYDRA_ID || 'manage',
15-
OSM_HYDRA_SECRET: process.env.OSM_HYDRA_SECRET || 'manage-secret',
16-
OSM_CONSUMER_KEY: process.env.OSM_CONSUMER_KEY,
17-
OSM_CONSUMER_SECRET: process.env.OSM_CONSUMER_SECRET,
18-
HYDRA_TOKEN_HOST: process.env.HYDRA_TOKEN_HOST || 'http://localhost:4444',
19-
HYDRA_TOKEN_PATH: process.env.HYDRA_TOKEN_PATH || '/oauth2/token',
20-
HYDRA_AUTHZ_HOST: process.env.HYDRA_AUTHZ_HOST || 'http://localhost:4444',
21-
HYDRA_AUTHZ_PATH: process.env.HYDRA_AUTHZ_PATH || '/oauth2/auth',
22-
HYDRA_ADMIN_HOST: process.env.HYDRA_ADMIN_HOST || 'http://localhost:4445',
2314
},
2415
basePath: process.env.BASE_PATH || '',
2516
env: {
2617
APP_URL: process.env.APP_URL || vercelUrl || 'http://127.0.0.1:3000',
2718
OSM_NAME: process.env.OSM_NAME || 'OSM',
2819
BASE_PATH: process.env.BASE_PATH || '',
20+
HYDRA_URL: process.env.HYDRA_URL || 'https://auth.mapping.team/hyauth',
21+
AUTH_URL: process.env.AUTH_URL || 'https://auth.mapping.team',
2922
},
3023
eslint: {
3124
dirs: [

oauth2-osm-client-app.png

-89.6 KB
Binary file not shown.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
"test:ava": "NODE_ENV=test ava",
3131
"lint": "next lint",
3232
"build": "next build",
33-
"start": "NODE_ENV=production node app/index.js",
3433
"postinstall": "yarn run next telemetry disable > /dev/null"
3534
},
3635
"browserify": {

src/components/tables/search-input.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const SearchInput = ({ onSearch, placeholder, 'data-cy': dataCy }) => {
5353
name='search'
5454
id='search'
5555
placeholder={placeholder}
56-
style={{ width: '12rem' }}
56+
style={{ width: '14rem' }}
5757
/>
5858
<Button
5959
data-cy={`${dataCy}-search-submit`}

src/components/tables/table.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ function TableHead({ dataCy, columns, sort, setSort, onClick }) {
1212
currentSortDirection === 'asc' ? 'desc' : 'asc'
1313
let sortIcon = ''
1414
if (currentSortDirection !== 'none') {
15-
sortIcon = currentSortDirection === 'asc' ? '' : ''
15+
sortIcon = currentSortDirection === 'asc' ? '' : ''
1616
}
1717

1818
return (
1919
<th
2020
key={`table-head-column-${key}`}
2121
data-cy={`${dataCy}-head-column-${key}`}
22+
className={sortable && 'sortable'}
23+
title={sortable && `Click to sort by ${key}`}
2224
onClick={() => {
2325
onClick && onClick()
2426

@@ -155,6 +157,9 @@ export default function Table({
155157
background: ${theme.colors.primaryLite};
156158
border-bottom: 4px solid ${theme.colors.primaryColor};
157159
}
160+
thead th.sortable {
161+
cursor: pointer;
162+
}
158163
159164
tbody tr td {
160165
padding: 0.875rem;

src/components/tables/users.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ function UsersTable({ type, orgId, onRowClick, isSearchable }) {
6666
setPage(1)
6767
setSearch(search)
6868
}}
69+
placeholder='Search by username'
6970
/>
7071
)}
7172
<Table

src/middlewares/base-handler.js

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import nc from 'next-connect'
22
import logger from '../lib/logger'
33
import { getToken } from 'next-auth/jwt'
4+
import Boom from '@hapi/boom'
45

56
/**
67
* This file contains the base handler to be used in all API routes.
@@ -67,9 +68,40 @@ export function createBaseHandler() {
6768

6869
// Add session to request
6970
baseHandler.use(async (req, res, next) => {
70-
const token = await getToken({ req })
71-
if (token) {
72-
req.session = { user_id: token.userId || token.sub }
71+
/** Handle authorization using either Bearer token auth or
72+
* using the next-auth session
73+
*/
74+
if (req.headers.authorization) {
75+
// introspect the token
76+
const [type, token] = req.headers.authorization.split(' ')
77+
if (type !== 'Bearer') {
78+
throw Boom.badRequest(
79+
'Authorization scheme not supported. Only Bearer scheme is supported'
80+
)
81+
} else {
82+
const result = await fetch(`${process.env.AUTH_URL}/api/introspect`, {
83+
method: 'POST',
84+
headers: {
85+
Accept: 'application/json',
86+
'Content-Type': 'application/json',
87+
},
88+
body: JSON.stringify({
89+
token: token,
90+
}),
91+
}).then((response) => {
92+
return response.json()
93+
})
94+
if (result && result.active) {
95+
req.session = { user_id: result.sub }
96+
} else {
97+
throw Boom.badRequest('Invalid token')
98+
}
99+
}
100+
} else {
101+
const token = await getToken({ req })
102+
if (token) {
103+
req.session = { user_id: token.userId || token.sub }
104+
}
73105
}
74106
next()
75107
})
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Boom from '@hapi/boom'
2+
3+
/**
4+
* Authenticated
5+
*
6+
* To view this route you must be authenticated
7+
*
8+
* @returns {Promise<boolean>}
9+
*/
10+
export default async function isAuthenticated(req, res, next) {
11+
const userId = req.session?.user_id
12+
13+
// Must be owner or manager
14+
if (!userId) {
15+
throw Boom.unauthorized()
16+
} else {
17+
next()
18+
}
19+
}

0 commit comments

Comments
 (0)