use crate::client::AgentTrustClient;
use crate::error::Result;
use crate::models::{
IntrospectTokenRequest, IntrospectionResult, IssueTokenRequest, IssueTokenResponse,
RevokeTokenRequest, Token,
};
pub struct TokensAPI<'a> {
pub(crate) client: &'a AgentTrustClient,
}
impl<'a> TokensAPI<'a> {
pub fn issue(&self, req: &IssueTokenRequest) -> Result<Token> {
let resp: IssueTokenResponse =
self.client
.request("POST", "/api/v1/agent-tokens/issue", Some(req))?;
Ok(resp.into_token())
}
pub fn introspect(&self, req: &IntrospectTokenRequest) -> Result<IntrospectionResult> {
let resp: IntrospectionResult =
self.client
.request("POST", "/api/v1/agent-tokens/introspect", Some(req))?;
Ok(resp)
}
#[deprecated(note = "Use TokensAPI::introspect")]
pub fn verify(&self, req: &IntrospectTokenRequest) -> Result<IntrospectionResult> {
self.introspect(req)
}
pub fn revoke(&self, token: &str, reason: &str) -> Result<()> {
let body = RevokeTokenRequest {
token: token.to_string(),
reason: reason.to_string(),
};
self.client
.request_no_response("POST", "/api/v1/agent-tokens/revoke", Some(&body))
}
}