Skip to content

Commit ba57bb1

Browse files
committed
feat: add support for openid
Closes #36
1 parent 770c537 commit ba57bb1

File tree

8 files changed

+18
-1
lines changed

8 files changed

+18
-1
lines changed

proto

src/api.rs

+3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ pub mod structs {
1212
pub refresh_token: String,
1313
#[serde(skip, default = "Utc::now")]
1414
pub obtain_time: DateTime<Utc>,
15+
#[serde(default)]
16+
pub scope: String
1517
}
1618
impl Token {
1719
pub fn new(access_token: String, refresh_token: String) -> Self {
1820
Self {
1921
access_token,
2022
refresh_token,
2123
obtain_time: Utc::now(),
24+
scope: String::new()
2225
}
2326
}
2427
}

src/api/gog/users.rs

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub async fn get_token_for(
77
client_secret: &str,
88
refresh_token: &str,
99
session: &Client,
10+
openid: bool,
1011
) -> Result<Token, Error> {
1112
let mut url = reqwest::Url::parse(
1213
"https://auth.gog.com/token?grant_type=refresh_token&without_new_session=1",
@@ -17,6 +18,10 @@ pub async fn get_token_for(
1718
.append_pair("client_secret", client_secret)
1819
.append_pair("refresh_token", refresh_token);
1920

21+
if openid {
22+
url.query_pairs_mut().append_pair("scope", "openid");
23+
}
24+
2025
let result = session
2126
.get(url)
2227
.timeout(time::Duration::from_secs(10))

src/api/handlers.rs

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ async fn sync_routine(
180180
client_secret,
181181
&token.refresh_token,
182182
reqwest_client,
183+
!token.scope.is_empty()
183184
)
184185
.await;
185186
match result {

src/api/handlers/communication_service.rs

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ async fn auth_info_request(
132132

133133
let client_id = request_data.client_id();
134134
let client_secret = request_data.client_secret();
135+
let openid = request_data.openid();
136+
135137
if !context.client_identified() {
136138
context.identify_client(client_id, client_secret);
137139
info!("Client identified as {} {}", client_id, client_secret);
@@ -153,6 +155,7 @@ async fn auth_info_request(
153155
client_secret,
154156
refresh_token.as_str(),
155157
reqwest_client,
158+
openid,
156159
)
157160
.await;
158161

src/api/handlers/context.rs

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ impl HandlerContext {
7070
client_id: &str,
7171
user_id: &str,
7272
) -> Result<(), sqlx::Error> {
73+
if self.db_connected {
74+
return Ok(());
75+
}
7376
let connection = db::gameplay::setup_connection(client_id, user_id).await?;
7477
self.db_connection = Some(connection);
7578

src/api/notification_pusher.rs

+1
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ impl NotificationPusherClient {
280280
}
281281
} else if msg_type == MessageType::MESSAGE_FROM_TOPIC.value() {
282282
info!("Recieved message from topic");
283+
log::debug!("Topic message: {:#?}", String::from_utf8_lossy(&msg_data));
283284
if let Err(error) = self.topic_sender.send(PusherEvent::Topic(msg_data)) {
284285
error!(
285286
"There was an error when forwarding topic message: {}",

src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ async fn main() {
169169
&client_secret,
170170
&refresh_token,
171171
&reqwest_client,
172+
false
172173
)
173174
.await
174175
.expect("Failed to obtain credentials");

0 commit comments

Comments
 (0)