Skip to content

Commit f66e754

Browse files
committed
oauth2: Adjust to breaking changes
1 parent e42ecf7 commit f66e754

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/app.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use diesel_async::pooled_connection::deadpool::Pool as DeadpoolPool;
1616
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
1717
use diesel_async::AsyncPgConnection;
1818
use oauth2::basic::BasicClient;
19+
use oauth2::{EndpointNotSet, EndpointSet};
1920

2021
type DeadpoolResult = Result<
2122
diesel_async::pooled_connection::deadpool::Object<AsyncPgConnection>,
@@ -35,7 +36,8 @@ pub struct App {
3536
pub github: Box<dyn GitHubClient>,
3637

3738
/// The GitHub OAuth2 configuration
38-
pub github_oauth: BasicClient,
39+
pub github_oauth:
40+
BasicClient<EndpointSet, EndpointNotSet, EndpointNotSet, EndpointNotSet, EndpointSet>,
3941

4042
/// The server configuration
4143
pub config: Arc<config::Server>,
@@ -70,14 +72,15 @@ impl App {
7072
let instance_metrics =
7173
InstanceMetrics::new().expect("could not initialize instance metrics");
7274

73-
let github_oauth = BasicClient::new(
74-
config.gh_client_id.clone(),
75-
Some(config.gh_client_secret.clone()),
76-
AuthUrl::new(String::from("https://github.com/login/oauth/authorize")).unwrap(),
77-
Some(
78-
TokenUrl::new(String::from("https://github.com/login/oauth/access_token")).unwrap(),
79-
),
80-
);
75+
let auth_url = "https://github.com/login/oauth/authorize";
76+
let auth_url = AuthUrl::new(auth_url.into()).unwrap();
77+
let token_url = "https://github.com/login/oauth/access_token";
78+
let token_url = TokenUrl::new(token_url.into()).unwrap();
79+
80+
let github_oauth = BasicClient::new(config.gh_client_id.clone())
81+
.set_client_secret(config.gh_client_secret.clone())
82+
.set_auth_uri(auth_url)
83+
.set_token_uri(token_url);
8184

8285
let primary_database = {
8386
use secrecy::ExposeSecret;

src/controllers/session.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use axum_extra::response::ErasedJson;
55
use diesel::prelude::*;
66
use diesel_async::{AsyncPgConnection, RunQueryDsl};
77
use http::request::Parts;
8-
use oauth2::reqwest::async_http_client;
98
use oauth2::{AuthorizationCode, CsrfToken, Scope, TokenResponse};
109

1110
use crate::app::AppState;
@@ -107,10 +106,14 @@ pub async fn authorize_session(
107106
}
108107

109108
// Fetch the access token from GitHub using the code we just got
109+
let client = reqwest::Client::builder()
110+
.redirect(reqwest::redirect::Policy::none())
111+
.build()?;
112+
110113
let token = app
111114
.github_oauth
112115
.exchange_code(query.code)
113-
.request_async(async_http_client)
116+
.request_async(&client)
114117
.await
115118
.map_err(|err| {
116119
req.request_log().add("cause", err);

0 commit comments

Comments
 (0)