Skip to content

Commit 52c264c

Browse files
committed
updates
1 parent edf628a commit 52c264c

6 files changed

Lines changed: 285 additions & 448 deletions

File tree

Cargo.lock

Lines changed: 246 additions & 408 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "dino-park-whoami"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["Florian Merz <flomerz@gmail.com>"]
55
edition = "2018"
66

@@ -10,22 +10,22 @@ localuserscope = ["dino_park_gate/localuserscope"]
1010

1111

1212
[dependencies]
13-
dino_park_gate = { git = "https://github.com/mozilla-iam/dino-park-gate", tag = "0.3.1", version = "0.3.1" }
14-
cis_client = { git = "https://github.com/mozilla-iam/cis_client-rust", branch = "0.4.0", version = "0.4.0", features = ["sync"] }
15-
cis_profile = { git = "https://github.com/mozilla-iam/cis_profile-rust", branch = "0.3.1", version = "0.3.1" }
13+
dino_park_gate = { git = "https://github.com/mozilla-iam/dino-park-gate", tag = "0.5.1", version = "0.5.1" }
14+
cis_client = { git = "https://github.com/mozilla-iam/cis_client-rust", tag = "0.5.0", version = "0.5.0", features = ["sync"] }
15+
cis_profile = { git = "https://github.com/mozilla-iam/cis_profile-rust", tag = "0.3.2", version = "0.3.2" }
16+
shared-expiry-get = "0.1.0"
1617
actix-web = "2.0"
1718
actix-rt = "1.0"
1819
actix-cors = "0.2"
1920
futures = "0.3"
20-
oauth2 = "2.0"
21-
url = "1.7"
21+
oauth2 = { version = "3.0.0-alpha.9", features = ["futures-03", "reqwest-010"], default-features = false }
22+
url = "2.1"
2223
base64 = "0.11"
2324
rand = "0.7"
2425
actix-session = "0.3"
2526
failure = "0.1"
2627
config = "0.10"
27-
serde = "1.0.80"
28-
serde_derive = "1.0.80"
28+
serde = { version = "1.0", features = ["derive"] }
2929
serde_json = "1.0.32"
3030
chrono = "0.4"
3131
env_logger = "0.7"

src/bugzilla/app.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use cis_client::AsyncCisClientTrait;
1515
use dino_park_gate::scope::ScopeAndUser;
1616
use log::info;
1717
use oauth2::basic::BasicClient;
18-
use oauth2::prelude::*;
1918
use oauth2::AuthUrl;
2019
use oauth2::ClientId;
2120
use oauth2::ClientSecret;
@@ -24,8 +23,8 @@ use oauth2::RedirectUrl;
2423
use oauth2::Scope;
2524
use oauth2::TokenUrl;
2625
use reqwest::Client;
26+
use serde::Deserialize;
2727
use std::sync::Arc;
28-
use url::Url;
2928

3029
const AUTH_PATH: &str = "/oauth/authorize";
3130
const TOKEN_PATH: &str = "/oauth/access_token";
@@ -45,7 +44,10 @@ pub struct BugZillaUser {
4544
}
4645

4746
async fn redirect(client: web::Data<Arc<BasicClient>>, session: Session) -> impl Responder {
48-
let (authorize_url, csrf_state) = client.authorize_url(CsrfToken::new_random);
47+
let (authorize_url, csrf_state) = client
48+
.authorize_url(CsrfToken::new_random)
49+
.add_scope(Scope::new("user:read".to_string()))
50+
.url();
4951
info!("settting: {}", csrf_state.secret());
5052
session
5153
.set("csrf_state", csrf_state.secret().clone())
@@ -121,14 +123,12 @@ pub fn bugzilla_app<T: AsyncCisClientTrait + 'static>(
121123
) -> impl HttpServiceFactory {
122124
let bugzilla_client_id = ClientId::new(bugzilla.client_id.clone());
123125
let bugzilla_client_secret = ClientSecret::new(bugzilla.client_secret.clone());
124-
let auth_url = AuthUrl::new(
125-
Url::parse(&format!("{}{}", &bugzilla.base_url, AUTH_PATH))
126-
.expect("Invalid authorization endpoint URL"),
127-
);
128-
let token_url = TokenUrl::new(
129-
Url::parse(&format!("{}{}", &bugzilla.base_url, TOKEN_PATH))
130-
.expect("Invalid token endpoint URL"),
131-
);
126+
let auth_url = AuthUrl::new(format!("{}{}", &bugzilla.base_url, AUTH_PATH))
127+
.expect("Invalid authorization endpoint URL");
128+
let token_url = TokenUrl::new(format!("{}{}", &bugzilla.base_url, TOKEN_PATH))
129+
.expect("Invalid token endpoint URL");
130+
let redirect_url = RedirectUrl::new(format!("https://{}/whoami/bugzilla/auth", whoami.domain))
131+
.expect("Invalid redirect URL");
132132

133133
let client = Arc::new(
134134
BasicClient::new(
@@ -137,11 +137,7 @@ pub fn bugzilla_app<T: AsyncCisClientTrait + 'static>(
137137
auth_url,
138138
Some(token_url),
139139
)
140-
.add_scope(Scope::new("user:read".to_string()))
141-
.set_redirect_url(RedirectUrl::new(
142-
Url::parse(&format!("https://{}/whoami/bugzilla/auth", whoami.domain))
143-
.expect("Invalid redirect URL"),
144-
)),
140+
.set_redirect_url(redirect_url),
145141
);
146142

147143
web::scope("/bugzilla/")

src/github/app.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use dino_park_gate::scope::ScopeAndUser;
1616
use failure::Error;
1717
use log::info;
1818
use oauth2::basic::BasicClient;
19-
use oauth2::prelude::*;
19+
use oauth2::reqwest::async_http_client;
20+
use oauth2::AsyncCodeTokenRequest;
2021
use oauth2::AuthUrl;
2122
use oauth2::AuthorizationCode;
2223
use oauth2::ClientId;
@@ -26,11 +27,12 @@ use oauth2::RedirectUrl;
2627
use oauth2::TokenResponse;
2728
use oauth2::TokenUrl;
2829
use reqwest::Client;
30+
use serde::Deserialize;
31+
use serde::Serialize;
2932
use std::sync::Arc;
3033
use std::sync::RwLock;
3134
use std::time::Duration;
3235
use ttl_cache::TtlCache;
33-
use url::Url;
3436

3537
const AUTH_URL: &str = "https://github.com/login/oauth/authorize";
3638
const TOKEN_URL: &str = "https://github.com/login/oauth/access_token";
@@ -59,7 +61,7 @@ pub struct GitHubUser {
5961

6062
async fn id_to_username(
6163
id: web::Path<String>,
62-
gtihub_auth_params: web::Data<GitHub>,
64+
github_auth_params: web::Data<GitHub>,
6365
cache: web::Data<Arc<RwLock<TtlCache<String, String>>>>,
6466
) -> Result<HttpResponse, Error> {
6567
if let Some(username) = cache.read().ok().and_then(|c| c.get(&*id).cloned()) {
@@ -71,8 +73,8 @@ async fn id_to_username(
7173
let res = Client::default()
7274
.get(&format!("{}/{}", USER_URL, id))
7375
.basic_auth(
74-
&gtihub_auth_params.client_id,
75-
Some(&gtihub_auth_params.client_secret),
76+
&github_auth_params.client_id,
77+
Some(&github_auth_params.client_secret),
7678
)
7779
.header(http::header::USER_AGENT, "whoami")
7880
.send()
@@ -90,7 +92,7 @@ async fn id_to_username(
9092
}
9193

9294
async fn redirect(client: web::Data<Arc<BasicClient>>, session: Session) -> impl Responder {
93-
let (authorize_url, csrf_state) = client.authorize_url(CsrfToken::new_random);
95+
let (authorize_url, csrf_state) = client.authorize_url(CsrfToken::new_random).url();
9496
info!("settting: {}", csrf_state.secret());
9597
session
9698
.set("csrf_state", csrf_state.secret().clone())
@@ -123,7 +125,10 @@ async fn auth<T: AsyncCisClientTrait + 'static>(
123125
.header(http::header::LOCATION, "/e?identityAdded=error")
124126
.finish());
125127
}
126-
let token_res = client.exchange_code(code);
128+
let token_res = client
129+
.exchange_code(code)
130+
.request_async(async_http_client)
131+
.await;
127132

128133
if let Ok(token) = token_res {
129134
let get = cis_client.clone();
@@ -167,8 +172,10 @@ pub fn github_app<T: AsyncCisClientTrait + 'static>(
167172
) -> impl HttpServiceFactory {
168173
let github_client_id = ClientId::new(github.client_id.clone());
169174
let github_client_secret = ClientSecret::new(github.client_secret.clone());
170-
let auth_url = AuthUrl::new(Url::parse(AUTH_URL).expect("Invalid authorization endpoint URL"));
171-
let token_url = TokenUrl::new(Url::parse(TOKEN_URL).expect("Invalid token endpoint URL"));
175+
let auth_url = AuthUrl::new(AUTH_URL.to_string()).expect("Invalid authorization endpoint URL");
176+
let token_url = TokenUrl::new(TOKEN_URL.to_string()).expect("Invalid token endpoint URL");
177+
let redirect_url = RedirectUrl::new(format!("https://{}/whoami/github/auth", whoami.domain))
178+
.expect("Invalid redirect URL");
172179

173180
let client = Arc::new(
174181
BasicClient::new(
@@ -177,10 +184,7 @@ pub fn github_app<T: AsyncCisClientTrait + 'static>(
177184
auth_url,
178185
Some(token_url),
179186
)
180-
.set_redirect_url(RedirectUrl::new(
181-
Url::parse(&format!("https://{}/whoami/github/auth", whoami.domain))
182-
.expect("Invalid redirect URL"),
183-
)),
187+
.set_redirect_url(redirect_url),
184188
);
185189

186190
web::scope("/github/")

src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#[macro_use]
2-
extern crate serde_derive;
3-
41
mod bugzilla;
52
mod github;
63
mod healthz;
@@ -40,6 +37,7 @@ async fn main() -> std::io::Result<()> {
4037
let provider = Provider::from_issuer("https://auth.mozilla.auth0.com/")
4138
.map_err(map_io_err)
4239
.await?;
40+
4341
HttpServer::new(move || {
4442
let scope_middleware = ScopeAndUserAuth {
4543
checker: provider.clone(),

src/settings.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use cis_client::settings::CisSettings;
22
use config::{Config, ConfigError, Environment, File};
3+
use serde::Deserialize;
34
use std::env;
45

56
#[derive(Debug, Deserialize, Clone)]

0 commit comments

Comments
 (0)