Starting to implement a very small solution for authentication (starting with RFC6749's password grant flow). Unfortunately I can't seem to hit an endpoint without succumbing to this error.
Here's my open licensed repo:
Server entrypoint scaffold to get you started using actix + diesel with a custom OAuth2 implementation.
Replication:
curl -X POST http://localhost:8080/token \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"grant_type": "password", "username": "user", "password": "pass"}'
hax10
October 23, 2024, 4:15am
2
grant_type: String,
username: Option<String>,
password: Option<String>,
client_id: Option<String>,
client_secret: Option<String>,
}
#[post("/token")]
async fn token(
pool: web::Data<DbPool>,
form: web::Form<TokenRequest>,
) -> Result<web::Json<Token>, AuthError> {
let mut conn = pool.get()?;
log::info!("POST /token");
if form.grant_type == "password" {
if let (Some(username_s), Some(password)) = (&form.username, &form.password) {
use crate::schema::users::dsl::*;
// Verify user credentials
let maybe_user: Option<User> = users
The /token
handler takes a form as its data, not a JSON structure. You should change web::Form
to web::Json
, or alternatively submit a form-urlencoded data payload, e.g.
curl --verbose -X POST http://localhost:8080/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
-d "grant_type=password&username=user&password=pass"
1 Like
Wow what a n00b mistake by me.
Thanks for the assist
system
Closed
January 21, 2025, 5:36pm
4
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.