Skip to content
This repository was archived by the owner on Jan 29, 2023. It is now read-only.

Commit 74ed758

Browse files
committed
⬆️ update for new auth from concourse 6
1 parent 7db6d57 commit 74ed758

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/concourse.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct TokenRequest<'a> {
4242
#[derive(Deserialize, Debug)]
4343
struct TokenResponse {
4444
access_token: String,
45+
id_token: Option<String>,
4546
}
4647

4748
impl Concourse {
@@ -59,6 +60,33 @@ impl Concourse {
5960
}
6061

6162
pub(crate) fn auth(mut self, username: &str, password: &str) -> Self {
63+
if let Ok(token) = reqwest::Url::parse(&format!("{}sky/issuer/token", self.url))
64+
.map_err(|_| ())
65+
.and_then(|url| {
66+
self.client
67+
.clone()
68+
.expect("error configuring HTTP client")
69+
.post(url)
70+
.basic_auth("fly", Some("Zmx5"))
71+
.form(&TokenRequest {
72+
grant_type: "password",
73+
username,
74+
password,
75+
scope: "openid profile email groups federated:id",
76+
})
77+
.send()
78+
.map_err(|_| ())
79+
.and_then(|req| req.json::<TokenResponse>().map_err(|_| ()))
80+
})
81+
{
82+
self.bearer = token.id_token;
83+
} else {
84+
self = self.old_auth(username, password);
85+
}
86+
self
87+
}
88+
89+
pub(crate) fn old_auth(mut self, username: &str, password: &str) -> Self {
6290
if let Ok(token) = reqwest::Url::parse(&format!("{}sky/token", self.url))
6391
.map_err(|_| ())
6492
.and_then(|url| {

0 commit comments

Comments
 (0)