Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Builtin basic auth fang #191

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add Note section for doc & add basic_auth example
  • Loading branch information
kana-rus committed Jun 26, 2024
commit 1969417ccf2da028871341ce616fecda2f4c1fd4
3 changes: 2 additions & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"hello",
"openai",
"realworld",
"basic_auth",
"quick_start",
"static_files",
"json_response",
Expand All @@ -20,4 +21,4 @@ tokio = { version = "1", features = ["full"] }
sqlx = { version = "0.7.3", features = ["runtime-tokio-native-tls", "postgres", "macros", "chrono", "uuid"] }
tracing = "0.1"
tracing-subscriber = "0.3"
chrono = "0.4"
chrono = "0.4"
8 changes: 8 additions & 0 deletions examples/basic_auth/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "basic_auth"
version = "0.1.0"
edition = "2021"

[dependencies]
ohkami = { workspace = true }
tokio = { workspace = true }
16 changes: 16 additions & 0 deletions examples/basic_auth/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use ohkami::prelude::*;
use ohkami::builtin::fang::BasicAuth;

#[tokio::main]
async fn main() {
Ohkami::new((
"/hello".GET(|| async {"Hello, public!"}),
"/private".By(Ohkami::with(
BasicAuth {
username: "master of hello",
password: "world"
},
"/hello".GET(|| async {"Hello, private :)"})
))
)).howl("localhost:8888").await
}
7 changes: 7 additions & 0 deletions ohkami/src/builtin/fang/basicauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ use crate::prelude::*;
/// - `[BasicAuth; N]` verifies each request to have one of the pairs of
/// `username` and `password`
///
/// <br>
///
/// Note : **NEVER** hardcode `username` and `password` in your code
/// if you are pushing your source code to GitHub or other public repository!!!
///
/// <br>
///
/// *example*
/// ```rust,no_run
/// use ohkami::prelude::*;
Expand Down
Loading