Skip to content

Commit 0ec25d9

Browse files
committed
fix: set async_trait(?Send)
1 parent 49f0b4a commit 0ec25d9

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

atcoder-problems-backend/src/server/auth.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ use actix_web::http::header::LOCATION;
77

88
const REDIRECT_URL: &str = "https://kenkoooo.com/atcoder/";
99

10-
#[async_trait]
10+
#[async_trait(?Send)]
1111
pub trait Authentication {
12-
async fn get_token(&self, code: &str) -> Result<String, reqwest::Error>;
13-
async fn get_user_id(&self, token: &str) -> Result<GitHubUserResponse, reqwest::Error>;
12+
async fn get_token(&self, code: &str) -> Result<String>;
13+
async fn get_user_id(&self, token: &str) -> Result<GitHubUserResponse>;
1414
}
1515

1616
#[derive(Serialize)]
@@ -37,9 +37,9 @@ pub struct GitHubAuthentication {
3737
client_secret: String,
3838
}
3939

40-
#[async_trait]
40+
#[async_trait(?Send)]
4141
impl Authentication for GitHubAuthentication {
42-
async fn get_token(&self, code: &str) -> Result<String, reqwest::Error> {
42+
async fn get_token(&self, code: &str) -> Result<String> {
4343
let request = TokenRequest {
4444
client_id: self.client_id.to_owned(),
4545
client_secret: self.client_secret.to_owned(),
@@ -51,21 +51,21 @@ impl Authentication for GitHubAuthentication {
5151
.header("Accept", "application/json")
5252
.json(&request)
5353
.send()
54-
.await?
54+
.await.map_err(error::ErrorInternalServerError)?
5555
.json()
56-
.await?;
56+
.await.map_err(error::ErrorInternalServerError)?;
5757
Ok(response.access_token)
5858
}
59-
async fn get_user_id(&self, access_token: &str) -> Result<GitHubUserResponse, reqwest::Error> {
59+
async fn get_user_id(&self, access_token: &str) -> Result<GitHubUserResponse> {
6060
let token_header = format!("token {}", access_token);
6161
let client = reqwest::Client::new();
6262
let response: GitHubUserResponse = client
6363
.get("https://api.github.com/user")
6464
.header("Authorization", token_header)
6565
.send()
66-
.await?
66+
.await.map_err(error::ErrorInternalServerError)?
6767
.json()
68-
.await?;
68+
.await.map_err(error::ErrorInternalServerError)?;
6969
Ok(response)
7070
}
7171
}

atcoder-problems-backend/src/server/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use crate::server::{AppData, Authentication};
22
use async_trait::async_trait;
33
use actix_web::{Result, cookie::Cookie, error};
44

5-
#[async_trait]
5+
#[async_trait(?Send)]
66
pub(crate) trait GetAuthId {
77
async fn get_authorized_id(&self, token: Option<Cookie<'static>>) -> Result<String>;
88
}
99

10-
#[async_trait]
10+
#[async_trait(?Send)]
1111
impl<A: Authentication + Clone + Send + Sync + 'static> GetAuthId for AppData<A> {
1212
async fn get_authorized_id(&self, token: Option<Cookie<'static>>) -> Result<String> {
1313
let client = self.authentication.clone();

0 commit comments

Comments
 (0)