[Rust/Rust Server] Fix example/test code (#19318)

* [Rust Server] Fix code so examples compile

Zero length arrays don't correctly type infer, so if we have no scopes, we need to not create a empty array

We need an authentication middleware - without it the code doesn't compile.

* Update samples

* [Rust Server] Remove trailing whitespace

* Update samples

* [Rust Server] [CI] Build all targets

* [Rust] Fix reqwest test
This commit is contained in:
Richard Whitehouse 2024-08-09 08:54:58 +01:00 committed by GitHub
parent 4b493358a8
commit ad7acc30eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
28 changed files with 347 additions and 341 deletions

View File

@ -34,4 +34,4 @@ jobs:
toolchain: stable toolchain: stable
- name: Build - name: Build
working-directory: ${{ matrix.sample }} working-directory: ${{ matrix.sample }}
run: cargo build run: cargo build --all-targets

View File

@ -26,6 +26,7 @@ import io.swagger.v3.oas.models.media.XML;
import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.parameters.RequestBody; import io.swagger.v3.oas.models.parameters.RequestBody;
import io.swagger.v3.oas.models.responses.ApiResponse; import io.swagger.v3.oas.models.responses.ApiResponse;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server; import io.swagger.v3.oas.models.servers.Server;
import joptsimple.internal.Strings; import joptsimple.internal.Strings;
import lombok.Setter; import lombok.Setter;
@ -1108,6 +1109,20 @@ public class RustServerCodegen extends AbstractRustCodegen implements CodegenCon
bundle.put("callbacks", callbackData); bundle.put("callbacks", callbackData);
} }
// Flag whether we have any OAuth scopes
Map<String, SecurityScheme> securitySchemeMap = openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null;
List<CodegenSecurity> authMethods = fromSecurity(securitySchemeMap);
boolean hasAuthScopes = false;
if (authMethods != null && !authMethods.isEmpty()) {
for (CodegenSecurity authMethod : authMethods) {
if (authMethod.hasScopes != null && authMethod.hasScopes) {
hasAuthScopes = true;
break;
}
}
}
bundle.put("hasAuthScopes", hasAuthScopes);
return super.postProcessSupportingFileData(bundle); return super.postProcessSupportingFileData(bundle);
} }

View File

@ -80,7 +80,6 @@ fn main() {
// In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server // In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server
// Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side. // Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side.
// See https://github.com/Keats/jsonwebtoken for more information // See https://github.com/Keats/jsonwebtoken for more information
let auth_token = build_token( let auth_token = build_token(
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
@ -90,13 +89,19 @@ fn main() {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. // In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
scopes: [ scopes:
{{#hasAuthScopes}}
[
{{#authMethods}} {{#authMethods}}
{{#scopes}} {{#scopes}}
"{{{scope}}}", "{{{scope}}}",
{{/scopes}} {{/scopes}}
{{/authMethods}} {{/authMethods}}
].join(", ") ].join::<&str>(", ")
{{/hasAuthScopes}}
{{^hasAuthScopes}}
"".to_owned()
{{/hasAuthScopes}}
}, },
b"secret").unwrap(); b"secret").unwrap();

View File

@ -15,6 +15,7 @@ use log::{error, debug};
/// Get a dummy claim with full permissions (all scopes) for testing purposes /// Get a dummy claim with full permissions (all scopes) for testing purposes
fn full_permission_claim() -> Claims { fn full_permission_claim() -> Claims {
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
company: "ACME".to_owned(), company: "ACME".to_owned(),
@ -22,14 +23,19 @@ fn full_permission_claim() -> Claims {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
// added a very long expiry time // added a very long expiry time
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. scopes:
scopes: [ {{#hasAuthScopes}}
[
{{#authMethods}} {{#authMethods}}
{{#scopes}} {{#scopes}}
"{{{scope}}}", "{{{scope}}}",
{{/scopes}} {{/scopes}}
{{/authMethods}} {{/authMethods}}
].join(", ") ].join::<&str>(", ")
{{/hasAuthScopes}}
{{^hasAuthScopes}}
"".to_owned()
{{/hasAuthScopes}}
} }
} }

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -12,7 +12,8 @@ fn test_types() {
double: 45.56, double: 45.56,
string: String::from("something"), string: String::from("something"),
boolean: true, boolean: true,
uuid: Uuid::new_v4() uuid: Uuid::new_v4(),
bytes: vec![1,2,3,4]
}; };
assert_eq!(type_of(tt.int32), "i32"); assert_eq!(type_of(tt.int32), "i32");
assert_eq!(type_of(tt.int64), "i64"); assert_eq!(type_of(tt.int64), "i64");

View File

@ -61,7 +61,6 @@ fn main() {
// In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server // In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server
// Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side. // Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side.
// See https://github.com/Keats/jsonwebtoken for more information // See https://github.com/Keats/jsonwebtoken for more information
let auth_token = build_token( let auth_token = build_token(
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
@ -71,8 +70,8 @@ fn main() {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. // In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
scopes: [ scopes:
].join(", ") "".to_owned()
}, },
b"secret").unwrap(); b"secret").unwrap();

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -15,6 +15,7 @@ use log::{error, debug};
/// Get a dummy claim with full permissions (all scopes) for testing purposes /// Get a dummy claim with full permissions (all scopes) for testing purposes
fn full_permission_claim() -> Claims { fn full_permission_claim() -> Claims {
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
company: "ACME".to_owned(), company: "ACME".to_owned(),
@ -22,9 +23,8 @@ fn full_permission_claim() -> Claims {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
// added a very long expiry time // added a very long expiry time
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. scopes:
scopes: [ "".to_owned()
].join(", ")
} }
} }

View File

@ -56,7 +56,6 @@ fn main() {
// In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server // In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server
// Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side. // Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side.
// See https://github.com/Keats/jsonwebtoken for more information // See https://github.com/Keats/jsonwebtoken for more information
let auth_token = build_token( let auth_token = build_token(
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
@ -66,8 +65,8 @@ fn main() {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. // In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
scopes: [ scopes:
].join(", ") "".to_owned()
}, },
b"secret").unwrap(); b"secret").unwrap();

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -15,6 +15,7 @@ use log::{error, debug};
/// Get a dummy claim with full permissions (all scopes) for testing purposes /// Get a dummy claim with full permissions (all scopes) for testing purposes
fn full_permission_claim() -> Claims { fn full_permission_claim() -> Claims {
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
company: "ACME".to_owned(), company: "ACME".to_owned(),
@ -22,9 +23,8 @@ fn full_permission_claim() -> Claims {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
// added a very long expiry time // added a very long expiry time
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. scopes:
scopes: [ "".to_owned()
].join(", ")
} }
} }

View File

@ -107,7 +107,6 @@ fn main() {
// In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server // In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server
// Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side. // Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side.
// See https://github.com/Keats/jsonwebtoken for more information // See https://github.com/Keats/jsonwebtoken for more information
let auth_token = build_token( let auth_token = build_token(
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
@ -117,10 +116,11 @@ fn main() {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. // In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
scopes: [ scopes:
[
"test.read", "test.read",
"test.write", "test.write",
].join(", ") ].join::<&str>(", ")
}, },
b"secret").unwrap(); b"secret").unwrap();

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -15,6 +15,7 @@ use log::{error, debug};
/// Get a dummy claim with full permissions (all scopes) for testing purposes /// Get a dummy claim with full permissions (all scopes) for testing purposes
fn full_permission_claim() -> Claims { fn full_permission_claim() -> Claims {
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
company: "ACME".to_owned(), company: "ACME".to_owned(),
@ -22,11 +23,11 @@ fn full_permission_claim() -> Claims {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
// added a very long expiry time // added a very long expiry time
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. scopes:
scopes: [ [
"test.read", "test.read",
"test.write", "test.write",
].join(", ") ].join::<&str>(", ")
} }
} }

View File

@ -129,7 +129,6 @@ fn main() {
// In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server // In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server
// Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side. // Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side.
// See https://github.com/Keats/jsonwebtoken for more information // See https://github.com/Keats/jsonwebtoken for more information
let auth_token = build_token( let auth_token = build_token(
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
@ -139,8 +138,8 @@ fn main() {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. // In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
scopes: [ scopes:
].join(", ") "".to_owned()
}, },
b"secret").unwrap(); b"secret").unwrap();

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -15,6 +15,7 @@ use log::{error, debug};
/// Get a dummy claim with full permissions (all scopes) for testing purposes /// Get a dummy claim with full permissions (all scopes) for testing purposes
fn full_permission_claim() -> Claims { fn full_permission_claim() -> Claims {
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
company: "ACME".to_owned(), company: "ACME".to_owned(),
@ -22,9 +23,8 @@ fn full_permission_claim() -> Claims {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
// added a very long expiry time // added a very long expiry time
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. scopes:
scopes: [ "".to_owned()
].join(", ")
} }
} }

View File

@ -115,7 +115,6 @@ fn main() {
// In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server // In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server
// Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side. // Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side.
// See https://github.com/Keats/jsonwebtoken for more information // See https://github.com/Keats/jsonwebtoken for more information
let auth_token = build_token( let auth_token = build_token(
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
@ -125,10 +124,11 @@ fn main() {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. // In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
scopes: [ scopes:
[
"write:pets", "write:pets",
"read:pets", "read:pets",
].join(", ") ].join::<&str>(", ")
}, },
b"secret").unwrap(); b"secret").unwrap();

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -15,6 +15,7 @@ use log::{error, debug};
/// Get a dummy claim with full permissions (all scopes) for testing purposes /// Get a dummy claim with full permissions (all scopes) for testing purposes
fn full_permission_claim() -> Claims { fn full_permission_claim() -> Claims {
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
company: "ACME".to_owned(), company: "ACME".to_owned(),
@ -22,11 +23,11 @@ fn full_permission_claim() -> Claims {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
// added a very long expiry time // added a very long expiry time
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. scopes:
scopes: [ [
"write:pets", "write:pets",
"read:pets", "read:pets",
].join(", ") ].join::<&str>(", ")
} }
} }

View File

@ -57,7 +57,6 @@ fn main() {
// In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server // In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server
// Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side. // Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side.
// See https://github.com/Keats/jsonwebtoken for more information // See https://github.com/Keats/jsonwebtoken for more information
let auth_token = build_token( let auth_token = build_token(
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
@ -67,8 +66,8 @@ fn main() {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. // In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
scopes: [ scopes:
].join(", ") "".to_owned()
}, },
b"secret").unwrap(); b"secret").unwrap();

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -15,6 +15,7 @@ use log::{error, debug};
/// Get a dummy claim with full permissions (all scopes) for testing purposes /// Get a dummy claim with full permissions (all scopes) for testing purposes
fn full_permission_claim() -> Claims { fn full_permission_claim() -> Claims {
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
company: "ACME".to_owned(), company: "ACME".to_owned(),
@ -22,9 +23,8 @@ fn full_permission_claim() -> Claims {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
// added a very long expiry time // added a very long expiry time
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. scopes:
scopes: [ "".to_owned()
].join(", ")
} }
} }

View File

@ -71,7 +71,6 @@ fn main() {
// In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server // In a real (production) system this Bearer token should be obtained via an external Identity/Authentication-server
// Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side. // Ensure that you set the correct algorithm and encodingkey that matches what is used on the server side.
// See https://github.com/Keats/jsonwebtoken for more information // See https://github.com/Keats/jsonwebtoken for more information
let auth_token = build_token( let auth_token = build_token(
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
@ -81,8 +80,8 @@ fn main() {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. // In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
scopes: [ scopes:
].join(", ") "".to_owned()
}, },
b"secret").unwrap(); b"secret").unwrap();

View File

@ -30,9 +30,7 @@ pub async fn create(addr: &str, https: bool) {
let service = MakeService::new(server); let service = MakeService::new(server);
// This pushes a fourth layer of the middleware-stack even though Swagger assumes only three levels. let service = MakeAllowAllAuthenticator::new(service, "cosmo");
// This fourth layer creates an accept-all policy, hower the example-code already acchieves the same via a Bearer-token with full permissions, so next line is not needed (anymore).
// let service = MakeAllowAllAuthenticator::new(service, "cosmo");
#[allow(unused_mut)] #[allow(unused_mut)]
let mut service = let mut service =

View File

@ -15,6 +15,7 @@ use log::{error, debug};
/// Get a dummy claim with full permissions (all scopes) for testing purposes /// Get a dummy claim with full permissions (all scopes) for testing purposes
fn full_permission_claim() -> Claims { fn full_permission_claim() -> Claims {
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization.
Claims { Claims {
sub: "tester@acme.com".to_owned(), sub: "tester@acme.com".to_owned(),
company: "ACME".to_owned(), company: "ACME".to_owned(),
@ -22,9 +23,8 @@ fn full_permission_claim() -> Claims {
aud: "org.acme.Resource_Server".to_string(), aud: "org.acme.Resource_Server".to_string(),
// added a very long expiry time // added a very long expiry time
exp: 10000000000, exp: 10000000000,
// In this example code all available Scopes are added, so the current Bearer Token gets fully authorization. scopes:
scopes: [ "".to_owned()
].join(", ")
} }
} }