Skip to content

Commit

Permalink
Merge pull request #164 from manomayam/webid-turtle
Browse files Browse the repository at this point in the history
fix: webid document serialization and deserialization
  • Loading branch information
sebadob committed Nov 11, 2023
2 parents dcbb832 + ae6db04 commit 1e32f6f
Show file tree
Hide file tree
Showing 13 changed files with 365 additions and 59 deletions.
17 changes: 17 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM mcr.microsoft.com/devcontainers/rust:1-1-bullseye

# Include lld linker to improve build times either by using environment variable
# RUSTFLAGS="-C link-arg=-fuse-ld=lld" or with Cargo's configuration file (i.e see .cargo/config.toml).
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install clang lld musl-tools \
&& apt-get autoremove -y && apt-get clean -y

## Install musl toolchain
RUN rustup target add x86_64-unknown-linux-musl

## Install cargo-binstall
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash

RUN cargo binstall sqlx-cli -qy

# RUN sudo chown -R vscode /usr/local/cargo/
55 changes: 55 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/rust-postgres
{
"name": "RAuthy dev container",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "lts",
"nvmVersion": "latest"
},
"ghcr.io/guiyomh/features/just:0": {
"version": "latest"
}
// "ghcr.io/lee-orr/rusty-dev-containers/cargo-binstall:0": {}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [5173],

"customizations": {
"vscode": {
// "settings": {
// "terminal.integrated.shell.linux": "/bin/bash"
// },
"extensions": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"streetsidesoftware.code-spell-checker",
"serayuzgur.crates",
"tamasfe.even-better-toml",
"christian-kohler.npm-intellisense",
"Swellaby.vscode-rust-test-adapter",
"rust-lang.rust-analyzer",
"ms-vscode.test-adapter-converter",
"hbenl.vscode-test-explorer",
"redhat.vscode-yaml"
]
}
}

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "rustc --version",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
37 changes: 37 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: '3.8'

volumes:
postgres-data:

services:
app:
build:
context: .
dockerfile: Dockerfile
env_file:
# Ensure that the variables in .env match the same variables in devcontainer.json
- .env

volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:db

# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)

db:
image: postgres:14.1
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
env_file:
# Ensure that the variables in .env match the same variables in devcontainer.json
- .env

# Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally.
# (Adding the "ports" property to this file will not forward from a Codespace.)
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/target
.idea
.vscode
.env
data
frontend/.next
Expand Down
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ clippy-postgres:

# re-create and migrate the sqlite database with sqlx
migrate-sqlite:
rm data/rauthy.db*
mkdir -p data/
rm -f data/rauthy.db*
DATABASE_URL={{db_url_sqlite}} sqlx database create
DATABASE_URL={{db_url_sqlite}} sqlx migrate run --source migrations/sqlite

Expand All @@ -104,6 +105,9 @@ migrate-postgres:
run-sqlite:
DATABASE_URL={{db_url_sqlite}} cargo run --target x86_64-unknown-linux-musl --features sqlite

# runs the application with sqlite feature, on native target
run-sqlite-native:
DATABASE_URL={{db_url_sqlite}} cargo run --features sqlite

# runs the application with postgres feature
run-postgres:
Expand Down
3 changes: 3 additions & 0 deletions rauthy-handlers/src/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ use utoipa::{openapi, OpenApi};
users::get_user_by_id,
users::get_user_attr,
users::put_user_attr,
users::get_user_webid,
users::get_user_webid_data,
users::put_user_webid_data,
users::get_user_password_reset,
users::put_user_password_reset,
users::post_webauthn_auth_start,
Expand Down
30 changes: 10 additions & 20 deletions rauthy-handlers/src/users.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{real_ip_from_req, ReqPrincipal};
use actix_web::http::header::CONTENT_TYPE;
use actix_web::http::StatusCode;
use actix_web::{cookie, delete, get, post, put, web, HttpRequest, HttpResponse, ResponseError};
use actix_web_validator::Json;
use rauthy_common::constants::{
APPLICATION_JSON, COOKIE_MFA, ENABLE_WEB_ID, HEADER_HTML, OPEN_USER_REG, PWD_RESET_COOKIE,
TEXT_TURTLE, USER_REG_DOMAIN_RESTRICTION,
COOKIE_MFA, ENABLE_WEB_ID, HEADER_HTML, OPEN_USER_REG, PWD_RESET_COOKIE, TEXT_TURTLE,
USER_REG_DOMAIN_RESTRICTION,
};
use rauthy_common::error_response::{ErrorResponse, ErrorResponseType};
use rauthy_common::utils::build_csp_header;
Expand Down Expand Up @@ -829,7 +828,7 @@ pub async fn post_webauthn_reg_finish(
}
}

/// Returns a user's webid, if enabled
/// Returns a user's webid document, if enabled
#[utoipa::path(
get,
path = "/users/{id}/webid",
Expand All @@ -844,7 +843,7 @@ pub async fn post_webauthn_reg_finish(
pub async fn get_user_webid(
data: web::Data<AppState>,
id: web::Path<String>,
req: HttpRequest,
_req: HttpRequest,
) -> Result<HttpResponse, ErrorResponse> {
// check if webid's are enabled globally
if !*ENABLE_WEB_ID {
Expand All @@ -865,27 +864,18 @@ 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,
language: user.language,
custom_data: webid.data,
};

let content_type = req
.headers()
.get(CONTENT_TYPE)
.map(|h| h.to_str().unwrap_or(TEXT_TURTLE))
.unwrap_or(TEXT_TURTLE);

if content_type == APPLICATION_JSON {
Ok(HttpResponse::Ok().json(resp))
} else {
// TODO serialize to turtle correctly
Ok(HttpResponse::Ok()
.content_type(TEXT_TURTLE)
.body(resp.as_turtle()))
}
// TODO content-negotiation based on `Accept` header.
resp.as_turtle()
.map(|content| HttpResponse::Ok().content_type(TEXT_TURTLE).body(content))
.map_err(|_| ErrorResponse::new(ErrorResponseType::Internal, "Invalid custom data".into()))
}

/// Returns data and options set by the user for the `webid` preferences
Expand Down Expand Up @@ -926,7 +916,7 @@ pub async fn get_user_webid_data(
Ok(HttpResponse::Ok().json(webid))
}

/// Returns data and options set by the user for the `webid` preferences
/// Returns data and options set by the user for the `webid` preferences. Data must be serialized in ntriples.
#[utoipa::path(
put,
path = "/users/{id}/webid/data",
Expand Down
3 changes: 3 additions & 0 deletions rauthy-models/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ webauthn-rs = { workspace = true }
webauthn-rs-proto = { workspace = true }
itertools = "0.11.0"
rsa = { version = "0.9.3", features = ["serde", "sha2"] }
rio_api = "0.8.4"
rio_turtle = "0.8.4"
serde_with = "3.4.0"

[dev-dependencies]
pretty_assertions = "1"
Expand Down
Loading

0 comments on commit 1e32f6f

Please sign in to comment.