@@ -5,6 +5,7 @@ use std::sync::RwLock;
55
66use actix_cors:: Cors ;
77use actix_web:: { http, web, App , HttpServer } ;
8+ use actix_web_httpauth:: middleware:: HttpAuthentication ;
89use anyhow:: Result ;
910use config:: Config ;
1011use error:: OLPError ;
@@ -14,6 +15,7 @@ use openhousepopulator::Buildings;
1415use osmpbfreader:: OsmPbfReader ;
1516use population:: InhabitantsMap ;
1617use serde:: Deserialize ;
18+ use alcoholic_jwt:: JWKS ;
1719
1820mod coverage;
1921mod error;
@@ -22,6 +24,7 @@ mod layers;
2224mod persistence;
2325mod population;
2426mod station;
27+ mod middleware;
2528
2629use coverage:: { CoverageMap , Method , Routing } ;
2730use layers:: streetgraph:: generate_streetgraph;
@@ -49,6 +52,7 @@ async fn station_info(
4952 request : web:: Json < StationInfoRequest > ,
5053 layers : web:: Data < RwLock < Layers > > ,
5154 streets : web:: Data < Streets > ,
55+ auth : web:: ReqData < middleware:: auth:: Claims >
5256) -> Result < InhabitantsMap , OLPError > {
5357 let merged_layers = layers
5458 . read ( )
@@ -101,13 +105,17 @@ async fn main() -> std::io::Result<()> {
101105 let config = Config :: builder ( )
102106 . set_default ( "cache.dir" , "./cache/" ) . unwrap ( )
103107 . set_default ( "data.dir" , "./pbf/" ) . unwrap ( )
108+ . set_default ( "oidc.issuer" , "https://dex.prod.k8s.xatellite.space" ) . unwrap ( )
104109 . add_source ( config:: File :: with_name ( "Config.toml" ) . required ( false ) )
105110 . build ( )
106111 . unwrap ( ) ;
107112
108113 let ( streets, buildings) = load_base_data ( & config) ;
109114 let layers = load_layers ( & config) ;
110115 let config = web:: Data :: new ( config) ;
116+ let jwks_data: JWKS = reqwest:: get ( format ! ( "{}/keys" , config. get_string( "oidc.issuer" ) . unwrap( ) ) ) . await . unwrap ( ) . json ( ) . await . unwrap ( ) ;
117+ log:: info!( "loaded jwks: {:?}" , jwks_data) ;
118+ let jwks = web:: Data :: new ( jwks_data) ;
111119
112120 log:: info!( "loading data done" ) ;
113121
@@ -126,12 +134,16 @@ async fn main() -> std::io::Result<()> {
126134 . allowed_header ( http:: header:: CONTENT_TYPE )
127135 . max_age ( 3600 ) ;
128136
137+ let authentication = HttpAuthentication :: bearer ( middleware:: auth:: validator) ;
138+
129139 App :: new ( )
130140 . wrap ( cors)
141+ . wrap ( authentication)
131142 . app_data ( layers. clone ( ) )
132143 . app_data ( streets. clone ( ) )
133144 . app_data ( buildings. clone ( ) )
134145 . app_data ( config. clone ( ) )
146+ . app_data ( jwks. clone ( ) )
135147 . route ( "/station-info" , web:: post ( ) . to ( station_info) )
136148 . route (
137149 "/coverage-info/{router}" ,
0 commit comments