allow website to not use a client secret
This commit is contained in:
parent
250cb9a509
commit
381610c2ec
1 changed files with 20 additions and 14 deletions
|
|
@ -59,19 +59,25 @@ pub async fn generate_token(
|
|||
form_data: Form<TokenRequest<'_>>
|
||||
) -> Result<Json<OAuthTokenResponse>, (Status, Json<OAuthErrorResponse>)> {
|
||||
|
||||
if form_data.client_id != Some("account") {
|
||||
return Err((
|
||||
Status::BadRequest,
|
||||
Json(OAuthErrorResponse { error: "invalid_client".to_string() })
|
||||
));
|
||||
}
|
||||
|
||||
let cl_secret: String = CLIENT_SECRET.clone();
|
||||
if form_data.client_secret != Some(&cl_secret) {
|
||||
return Err((
|
||||
Status::Unauthorized,
|
||||
Json(OAuthErrorResponse { error: "invalid_client".to_string() })
|
||||
));
|
||||
match form_data.client_id {
|
||||
Some("account") | Some("splatnet") => {
|
||||
let cl_secret: String = CLIENT_SECRET.clone();
|
||||
if form_data.client_secret != Some(&cl_secret) {
|
||||
return Err((
|
||||
Status::Unauthorized,
|
||||
Json(OAuthErrorResponse { error: "invalid_client".to_string() })
|
||||
));
|
||||
}
|
||||
}
|
||||
Some("website") => {
|
||||
// no secret for this client, cant be kept confidential in the case of the website
|
||||
}
|
||||
_ => {
|
||||
return Err((
|
||||
Status::BadRequest,
|
||||
Json(OAuthErrorResponse { error: "invalid_client".to_string() })
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// i'm only supporting the password grant incase someone feels lazy.
|
||||
|
|
@ -163,4 +169,4 @@ pub async fn generate_token(
|
|||
token_type: "Bearer".to_string(),
|
||||
expires_in: 3600,
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue