-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Support audience #99
Comments
I'm happy to review a PR for this. Would this be applicable across authentication methods, or only for custom service accounts? If the latter, see discussion in #92. |
#106 should provide a clear pattern for this if you're still interested. |
Hi @djc, Design ReviewIf so, based on what you suggested #106, I will modify below pub struct CustomServiceAccount {
...
audience: Option<String>,
}
impl CustomServiceAccount {
...
/// Set the `Audience` to impersonate a user
pub fn with_audience(mut self, audience: String) -> Self {
self.audience = Some(audience);
self
}
fn new(credentials: ServiceAccountKey, client: HttpClient) -> Result<Self, Error> {
debug!(project = ?credentials.project_id, email = credentials.client_email, "found credentials");
Ok(Self {
...
audience: None,
})
}
async fn fetch_token(&self, scopes: &[&str]) -> Result<Arc<Token>, Error> {
let jwt =
Claims::new(&self.credentials, scopes, self.subject.as_deref(), self.audience.as_deref()).to_jwt(&self.signer)?;
...
}
}
impl<'a> Claims<'a> {
pub(crate) fn new(key: &'a ServiceAccountKey, scopes: &[&str], sub: Option<&'a str>, aud: Option<&'a str>) -> Self {
...
let aud = if let Some(aud_str) = aud {
aud_str
} else {
&key.token_uri
};
Claims {
iss: &key.client_email,
aud,
exp: iat + 3600 - 5, // Max validity is 1h
iat,
sub,
scope,
}
}
...
} |
I think doing |
When invoking Cloud Run endpoints, token needs to have audience of the endpoint url.
The text was updated successfully, but these errors were encountered: