From 8c6f6f6456a18fd8ab41ca2a64b45b154a94f4aa Mon Sep 17 00:00:00 2001 From: jbtrystram Date: Fri, 2 Dec 2022 11:10:55 +0100 Subject: [PATCH 1/2] initial changes for personnal access token scopes --- Cargo.toml | 2 +- src/auth/openid/mod.rs | 1 + src/auth/user.rs | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 81b3eb0..cea9b7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ tokio-postgres = { version = "0.7", features = ["runtime", "with-serde_json-1", #actix-web = { git = "https://github.com/ctron/actix-web", rev = "f3f41a0cc70e43564f8243b3ff425195566b5f16" } # FIXME: awaiting release 4.2.0 #actix-http = { git = "https://github.com/ctron/actix-web", rev = "f3f41a0cc70e43564f8243b3ff425195566b5f16" } # FIXME: awaiting release 4.2.0 -drogue-client = { git = "https://github.com/drogue-iot/drogue-client", rev = "798c968f0a63a0debcff9965c66b361e85946458" } # FIXME: awaiting release 0.11.0 +drogue-client = { git = "https://github.com/drogue-iot/drogue-client", rev = "fdebb42a6cbaa872a779e892fefe0f687b34fa4b" } # FIXME: awaiting release 0.11.0 #drogue-client = { path = "../drogue-client" } [features] diff --git a/src/auth/openid/mod.rs b/src/auth/openid/mod.rs index 45407ec..8abd33f 100644 --- a/src/auth/openid/mod.rs +++ b/src/auth/openid/mod.rs @@ -50,6 +50,7 @@ impl From for UserDetails { Self { user_id: claims.standard_claims.sub, roles, + scopes: None, } } } diff --git a/src/auth/user.rs b/src/auth/user.rs index 7579871..a4841af 100644 --- a/src/auth/user.rs +++ b/src/auth/user.rs @@ -1,5 +1,6 @@ //! Structures to work with users and identities. +use drogue_client::tokens::v1::AccessTokenScopes; use drogue_client::user::v1::UserDetails; /// Information about the authenticated user, may be anonymous @@ -26,6 +27,13 @@ impl UserInformation { Self::Anonymous => &EMPTY_ROLES, } } + + pub fn token_scopes(&self) -> Option<&AccessTokenScopes> { + match self { + Self::Authenticated(details) => details.scopes.as_ref(), + Self::Anonymous => None, + } + } } /// Extractor for user information. From 2f4265a445bcbc10e1a2c2fe03fc4dd032eb7d49 Mon Sep 17 00:00:00 2001 From: jbtrystram Date: Mon, 12 Dec 2022 07:50:00 +0100 Subject: [PATCH 2/2] impl access tokens claims --- Cargo.toml | 4 ++-- src/auth/openid/mod.rs | 2 +- src/auth/user.rs | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cea9b7b..07abe10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,8 +67,8 @@ tokio-postgres = { version = "0.7", features = ["runtime", "with-serde_json-1", #actix-web = { git = "https://github.com/ctron/actix-web", rev = "f3f41a0cc70e43564f8243b3ff425195566b5f16" } # FIXME: awaiting release 4.2.0 #actix-http = { git = "https://github.com/ctron/actix-web", rev = "f3f41a0cc70e43564f8243b3ff425195566b5f16" } # FIXME: awaiting release 4.2.0 -drogue-client = { git = "https://github.com/drogue-iot/drogue-client", rev = "fdebb42a6cbaa872a779e892fefe0f687b34fa4b" } # FIXME: awaiting release 0.11.0 -#drogue-client = { path = "../drogue-client" } +#drogue-client = { git = "https://github.com/drogue-iot/drogue-client", rev = "fdebb42a6cbaa872a779e892fefe0f687b34fa4b" } # FIXME: awaiting release 0.11.0 +drogue-client = { path = "../drogue-client" } [features] default = ["default-tls", "actix", "openssl", "app", "postgres"] diff --git a/src/auth/openid/mod.rs b/src/auth/openid/mod.rs index 8abd33f..05dd591 100644 --- a/src/auth/openid/mod.rs +++ b/src/auth/openid/mod.rs @@ -50,7 +50,7 @@ impl From for UserDetails { Self { user_id: claims.standard_claims.sub, roles, - scopes: None, + claims: None, } } } diff --git a/src/auth/user.rs b/src/auth/user.rs index a4841af..f8ae4e0 100644 --- a/src/auth/user.rs +++ b/src/auth/user.rs @@ -1,6 +1,6 @@ //! Structures to work with users and identities. -use drogue_client::tokens::v1::AccessTokenScopes; +use drogue_client::tokens::v1::AccessTokenClaims; use drogue_client::user::v1::UserDetails; /// Information about the authenticated user, may be anonymous @@ -28,9 +28,9 @@ impl UserInformation { } } - pub fn token_scopes(&self) -> Option<&AccessTokenScopes> { + pub fn token_claims(&self) -> Option<&AccessTokenClaims> { match self { - Self::Authenticated(details) => details.scopes.as_ref(), + Self::Authenticated(details) => details.claims.as_ref(), Self::Anonymous => None, } }