Skip to content

Commit

Permalink
Apply suggestions for webid support
Browse files Browse the repository at this point in the history
  • Loading branch information
damooo committed Nov 11, 2023
1 parent 3547757 commit ae6db04
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 32 deletions.
3 changes: 0 additions & 3 deletions rauthy-common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ lazy_static! {
};
format!("{}://{}", scheme, *PUB_URL)
};
pub static ref OIDC_ISSUER: String = {
format!("{}/auth/v1/", *PUB_URL_WITH_SCHEME)
};
pub static ref DPOP_TOKEN_ENDPOINT: Uri = {
let scheme = if *DEV_MODE && *DEV_DPOP_HTTP { "http" } else { "https" };
let uri = format!("{}://{}/auth/v1/oidc/token", scheme, *PUB_URL);
Expand Down
16 changes: 0 additions & 16 deletions rauthy-common/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::constants::PUB_URL_WITH_SCHEME;
use crate::error_response::{ErrorResponse, ErrorResponseType};
use actix_web::HttpRequest;
use base64::{engine, engine::general_purpose, Engine as _};
Expand Down Expand Up @@ -193,21 +192,6 @@ where
Ok(claims)
}

/// Resolve webid uri
#[inline]
pub fn resolve_webid_uri(user_id: &str) -> String {
format!(
"{}/auth/v1/users/{}/webid#me",
*PUB_URL_WITH_SCHEME, user_id
)
}

/// Resolve webid card uri.
#[inline]
pub fn resolve_webid_card_uri(user_id: &str) -> String {
format!("{}/auth/v1/users/{}/webid", *PUB_URL_WITH_SCHEME, user_id)
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions rauthy-handlers/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ pub async fn get_user_webid(

let resp = WebIdResponse {
user_id: user.id,
issuer: data.issuer.clone(),
email: user.email,
given_name: user.given_name,
family_name: user.family_name,
Expand Down
17 changes: 16 additions & 1 deletion rauthy-models/src/entity/webids.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::app_state::AppState;
use actix_web::web;
use rauthy_common::constants::CACHE_NAME_12HR;
use rauthy_common::constants::{CACHE_NAME_12HR, PUB_URL_WITH_SCHEME};
use rauthy_common::error_response::ErrorResponse;
use redhac::{cache_get, cache_get_from, cache_get_value, cache_insert, AckLevel};
use rio_api::{model::Triple, parser::TriplesParser};
Expand Down Expand Up @@ -94,6 +94,21 @@ pub struct WebId {
}

impl WebId {
/// Resolve webid uri
#[inline]
pub fn resolve_webid_uri(user_id: &str) -> String {
format!(
"{}/auth/v1/users/{}/webid#me",
*PUB_URL_WITH_SCHEME, user_id
)
}

/// Resolve webid card uri.
#[inline]
pub fn resolve_webid_card_uri(user_id: &str) -> String {
format!("{}/auth/v1/users/{}/webid", *PUB_URL_WITH_SCHEME, user_id)
}

pub async fn find(data: &web::Data<AppState>, user_id: String) -> Result<Self, ErrorResponse> {
if let Some(web_id) = cache_get!(
Self,
Expand Down
15 changes: 7 additions & 8 deletions rauthy-models/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ use crate::entity::sessions::SessionState;
use crate::entity::user_attr::{UserAttrConfigEntity, UserAttrValueEntity};
use crate::entity::users::{AccountType, User};
use crate::entity::webauthn::PasskeyEntity;
use crate::entity::webids::NTriplesGraph;
use crate::entity::webids::{NTriplesGraph, WebId};
use crate::language::Language;
use crate::JktClaim;
use rauthy_common::constants::OIDC_ISSUER;
use rauthy_common::utils::{resolve_webid_card_uri, resolve_webid_uri};
use rio_api::formatter::TriplesFormatter;
use rio_api::model::{Literal, NamedNode, Subject, Term, Triple};
use rio_turtle::{TurtleError, TurtleFormatter};
Expand Down Expand Up @@ -478,6 +476,7 @@ pub struct WebauthnLoginResponse {
#[derive(Debug, Serialize, ToSchema)]
pub struct WebIdResponse {
pub user_id: String,
pub issuer: String,
pub email: String,
pub given_name: String,
pub family_name: String,
Expand All @@ -497,10 +496,10 @@ impl WebIdResponse {
/// Serialize the webid response to a graph serializable syntax.
fn serialize<F: TriplesFormatter>(&self, formatter: &mut F) -> Result<(), F::Error> {
let t_user = NamedNode {
iri: &resolve_webid_uri(&self.user_id),
iri: &WebId::resolve_webid_uri(&self.user_id),
};
let t_card = NamedNode {
iri: &resolve_webid_card_uri(&self.user_id),
iri: &WebId::resolve_webid_card_uri(&self.user_id),
};
let t_type = "http://www.w3.org/1999/02/22-rdf-syntax-ns#type";

Expand All @@ -521,7 +520,7 @@ impl WebIdResponse {
formatter.format(&Self::triple(
t_user,
"http://www.w3.org/ns/solid/terms#oidcIssuer",
NamedNode { iri: &*OIDC_ISSUER },
NamedNode { iri: &self.issuer },
))?;

// rdf:type
Expand All @@ -547,8 +546,8 @@ impl WebIdResponse {
formatter.format(&Self::triple(
t_user,
"http://xmlns.com/foaf/0.1/mbox",
Literal::Simple {
value: &self.given_name,
NamedNode {
iri: &format!("mailto:{}", &self.email),
},
))?;

Expand Down
6 changes: 2 additions & 4 deletions rauthy-service/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use rauthy_common::constants::{
};
use rauthy_common::error_response::{ErrorResponse, ErrorResponseType};
use rauthy_common::password_hasher::HashPassword;
use rauthy_common::utils::{
base64_url_encode, encrypt, get_client_ip, get_rand, resolve_webid_uri,
};
use rauthy_common::utils::{base64_url_encode, encrypt, get_client_ip, get_rand};
use rauthy_models::app_state::AppState;
use rauthy_models::entity::auth_codes::AuthCode;
use rauthy_models::entity::clients::Client;
Expand Down Expand Up @@ -477,7 +475,7 @@ pub async fn build_id_token(
.unwrap_or(false);

if is_open {
Some(resolve_webid_uri(&user.id))
Some(WebId::resolve_webid_uri(&user.id))
} else {
None
}
Expand Down

0 comments on commit ae6db04

Please sign in to comment.