Skip to content
Snippets Groups Projects
Verified Commit 81411083 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

[PAM] Make client_secret and token_url optional

parent 914f69c1
No related branches found
No related tags found
No related merge requests found
......@@ -53,9 +53,25 @@ fn get_or_pam_error(config: &Config, key: &str) -> Result<String, PamError> {
}
}
fn get_optional(config: &Config, key: &str) -> Option<String> {
match config.get_str(key) {
Ok(v) => {
debug!("Configuration key found: {} = {}", key, v);
return Some(v);
},
Err(_) => {
debug!("Configuration key not found (optional): {}", key);
return None;
},
}
}
fn do_legacy_auth(username: String, password: String, config: Config) -> Result<BasicTokenResponse, PamError> {
let client_id = ClientId::new(get_or_pam_error(&config, "pam.client_id")?);
let client_secret = ClientSecret::new(get_or_pam_error(&config, "pam.client_secret")?);
let client_secret = match get_optional(&config, "pam.client_secret") {
Some(v) => Some(ClientSecret::new(v)),
None => None,
};
let auth_url = match AuthUrl::new(get_or_pam_error(&config, "pam.auth_url")?) {
Ok(u) => u,
_ => {
......@@ -63,16 +79,19 @@ fn do_legacy_auth(username: String, password: String, config: Config) -> Result<
return Err(PamError::SERVICE_ERR);
},
};
let token_url = match TokenUrl::new(get_or_pam_error(&config, "pam.token_url")?){
Ok(u) => u,
_ => {
error!("Could not parse token URL");
return Err(PamError::SERVICE_ERR);
let token_url = match get_optional(&config, "pam.token_url") {
Some(v) => match TokenUrl::new(v) {
Ok(u) => Some(u),
Err(_) => {
error!("Could not parse token URL");
return Err(PamError::SERVICE_ERR);
}
},
None => None,
};
let scope = get_or_pam_error(&config, "pam.scope")?;
let client = BasicClient::new(client_id, Some(client_secret), auth_url, Some(token_url));
let client = BasicClient::new(client_id, client_secret, auth_url, token_url);
let result = client
.exchange_password(
&ResourceOwnerUsername::new(username),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment