Skip to content

Commit bb892d7

Browse files
committed
configuration for keycloak working with exchange token
1 parent 448b195 commit bb892d7

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

beacon/__main__.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,31 @@ async def post(self):
140140
except Exception as e:# pragma: no cover
141141
response_obj = build_beacon_error_response(self, ErrorClass.error_code, 'prova', ErrorClass.error_response)
142142
return web.Response(text=json_util.dumps(response_obj), status=ErrorClass.error_code, content_type='application/json')
143+
144+
class WellKnown(EndpointView):
145+
@log_with_args(level)
146+
async def info(self, request):
147+
try:
148+
response_obj = {"resource": "http://beaconprod:5050/api/",
149+
"authorization_servers": ["http://idp:8080/auth/realms/Beacon/"],
150+
"client_id": "beacon"}
151+
return web.Response(text=json_util.dumps(response_obj), status=200, content_type='application/json')
152+
except Exception:# pragma: no cover
153+
raise
154+
155+
async def get(self):
156+
try:
157+
return await self.info(self.request)
158+
except Exception as e:# pragma: no cover
159+
response_obj = build_beacon_error_response(self, ErrorClass.error_code, 'prova', ErrorClass.error_response)
160+
return web.Response(text=json_util.dumps(response_obj), status=ErrorClass.error_code, content_type='application/json')
161+
162+
async def post(self):
163+
try:
164+
return await self.info(self.request)
165+
except Exception as e:# pragma: no cover
166+
response_obj = build_beacon_error_response(self, ErrorClass.error_code, 'prova', ErrorClass.error_response)
167+
return web.Response(text=json_util.dumps(response_obj), status=ErrorClass.error_code, content_type='application/json')
143168

144169
class Collection(EndpointView):
145170
@log_with_args(level)
@@ -305,6 +330,7 @@ async def create_api():# pragma: no cover
305330

306331
app.add_routes([web.post('/api', Info)])
307332
app.add_routes([web.post('/api/info', Info)])
333+
app.add_routes([web.post('/api/.well-known/oauth-protected-resource', WellKnown)])
308334
app.add_routes([web.post('/api/entry_types', EntryTypes)])
309335
app.add_routes([web.post('/api/service-info', ServiceInfo)])
310336
app.add_routes([web.post('/api/configuration', Configuration)])
@@ -348,6 +374,7 @@ async def create_api():# pragma: no cover
348374
app.add_routes([web.post('/api/runs/{id}/g_variants', Resultset)])
349375
app.add_routes([web.get('/api', Info)])
350376
app.add_routes([web.get('/api/info', Info)])
377+
app.add_routes([web.get('/api/.well-known/oauth-protected-resource', WellKnown)])
351378
app.add_routes([web.get('/api/entry_types', EntryTypes)])
352379
app.add_routes([web.get('/api/service-info', ServiceInfo)])
353380
app.add_routes([web.get('/api/configuration', Configuration)])

beacon/auth/__main__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from aiohttp import web
66
import os
77
from dotenv import load_dotenv
8-
from beacon.logs.logs import log_with_args
8+
from beacon.logs.logs import log_with_args, LOG
99
from beacon.conf.conf import level
1010

1111
@log_with_args(level)
@@ -37,6 +37,7 @@ def validate_access_token(self, access_token, idp_issuer, jwks_url, algorithm, a
3737
@log_with_args(level)
3838
def fetch_idp(self, access_token):
3939
try:
40+
LOG.debug(access_token)
4041
header = jwt.get_unverified_header(access_token)
4142
algorithm=header["alg"]
4243
decoded = jwt.decode(access_token, options={"verify_signature": False})

docker-compose.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ version: '3.1'
33
networks:
44
idp-priv:
55
pub:
6+
my-app-network:
7+
external: True
68

79
services:
810
beaconprod:
@@ -18,6 +20,7 @@ services:
1820
- ./beacon/permissions:/beacon/permissions
1921
networks:
2022
- pub
23+
- my-app-network
2124

2225
idp:
2326
#image: quay.io/keycloak/keycloak:12.0.0
@@ -38,19 +41,20 @@ services:
3841
- DB_DATABASE=keycloak
3942
#- DB_SCHEMA=public
4043
- KEYCLOAK_IMPORT=/tmp/beacon-realm.json -Dkeycloak.profile.feature.upload_scripts=enabled -Dkeycloak.profile.feature.token_exchange=enabled -Dkeycloak.profile.feature.admin_fine_grained_authz=enabled
41-
- KEYCLOAK_HOSTNAME=localhost
44+
- KC_HOSTNAME=idp
4245
#- KC_HOSTNAME_URL=https://beacon-network-test2.ega-archive.org
4346
#- KC_HOSTNAME_ADMIN_URL=https://beacon-network-test2.ega-archive.org
4447
#- KEYCLOAK_FRONTEND_URL=https://beacon-network-test2.ega-archive.org/auth/
4548
#- PROXY_ADDRESS_FORWARDING=true
4649
volumes:
4750
- ./beacon/auth/realms/beacon-realm.json:/tmp/beacon-realm.json
4851
ports:
49-
- "8080:8080"
52+
- "8070:8080"
5053
- "9991:8443"
5154
networks:
5255
- idp-priv
5356
- pub
57+
- my-app-network
5458
depends_on:
5559
- idp-db
5660

0 commit comments

Comments
 (0)