-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add introspect (can hopefully be used for NGINX) #174
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -170,6 +170,27 @@ async fn normal_flow() { | |||||
|
||||||
assert_eq!(response.status(), Status::SeeOther); | ||||||
|
||||||
let credentials = | ||||||
base64::encode(&format!("{}:{}", client_id, client.secret)); | ||||||
|
||||||
let form_body = format!("token=1234"); | ||||||
let req = http_client | ||||||
.post("/oauth/introspect") | ||||||
.header(ContentType::Form) | ||||||
.header(Header::new( | ||||||
"Authorization", | ||||||
format!("Basic {}", credentials), | ||||||
)) | ||||||
.body(form_body); | ||||||
|
||||||
let response = req.dispatch().await; | ||||||
assert_eq!(response.status(), Status::Ok); | ||||||
let response_body = | ||||||
response.into_string().await.expect("response body"); | ||||||
let data: Value = | ||||||
serde_json::from_str(&response_body).expect("response json values"); | ||||||
assert_eq!(data["active"], false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// 7a. Client requests access code while sending its credentials | ||||||
// trough HTTP Auth. | ||||||
let token_url = "/oauth/token"; | ||||||
|
@@ -178,9 +199,6 @@ async fn normal_flow() { | |||||
authorization_code, redirect_uri | ||||||
); | ||||||
|
||||||
let credentials = | ||||||
base64::encode(&format!("{}:{}", client_id, client.secret)); | ||||||
|
||||||
let req = http_client | ||||||
.post(token_url) | ||||||
.header(ContentType::Form) | ||||||
|
@@ -256,6 +274,24 @@ async fn normal_flow() { | |||||
assert_eq!(data["token_type"], "bearer"); | ||||||
let token = data["access_token"].as_str().expect("access token"); | ||||||
|
||||||
let form_body = format!("token={}", token); | ||||||
let req = http_client | ||||||
.post("/oauth/introspect") | ||||||
.header(ContentType::Form) | ||||||
.header(Header::new( | ||||||
"Authorization", | ||||||
format!("Basic {}", credentials), | ||||||
)) | ||||||
.body(form_body); | ||||||
|
||||||
let response = req.dispatch().await; | ||||||
assert_eq!(response.status(), Status::Ok); | ||||||
let response_body = | ||||||
response.into_string().await.expect("response body"); | ||||||
let data: Value = | ||||||
serde_json::from_str(&response_body).expect("response json values"); | ||||||
assert_eq!(data["active"], true); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
let response = http_client | ||||||
.get("/current_user") | ||||||
.header(Accept::JSON) | ||||||
|
@@ -276,6 +312,26 @@ async fn normal_flow() { | |||||
|
||||||
assert!(data["id"].is_number()); | ||||||
assert_eq!(data["username"], user_username); | ||||||
|
||||||
http_client.post("/logout").dispatch().await; | ||||||
|
||||||
let form_body = format!("token=1234"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think you meant to test if the token is invalidated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes and the test fails 😢 |
||||||
let req = http_client | ||||||
.post("/oauth/introspect") | ||||||
.header(ContentType::Form) | ||||||
.header(Header::new( | ||||||
"Authorization", | ||||||
format!("Basic {}", credentials), | ||||||
)) | ||||||
.body(form_body); | ||||||
|
||||||
let response = req.dispatch().await; | ||||||
assert_eq!(response.status(), Status::Ok); | ||||||
let response_body = | ||||||
response.into_string().await.expect("response body"); | ||||||
let data: Value = | ||||||
serde_json::from_str(&response_body).expect("response json values"); | ||||||
assert_eq!(data["active"], false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
}) | ||||||
.await; | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is missing the following check required by the RFC:
With the current code, any client could try to fish for valid tokens.
The other checks required are checked by the
Session::find_by_key
function (token is not expired, not invalidated, ...).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'll look at it at a later time, I don't think this pr is high prio