CreateOAuthToken Endpoint
Hiya I'm currently working on something to Create an OAuthToken Endpoint.
But this specific Endpoint it isn't callable via the Rest or GraphQL path.
I wanted to ask if it is possible to access the host parameter from within the endpoint function. So I don't have to send the base_url parameter
use derive_builder::Builder;
use gitlab::api::endpoint_prelude::*;
/// Delete an impersonation_token.
#[derive(Debug, Builder, Clone)]
pub struct CreateOAuthToken<'a> {
#[builder(setter(into))]
base_url: Cow<'a, str>,
/// The Username to authenticate with.
#[builder(setter(into))]
username: Cow<'a, str>,
/// The Password to authenticate with.
#[builder(setter(into))]
password: Cow<'a, str>,
}
impl<'a> CreateOAuthToken<'a> {
/// Create a builder for the endpoint.
pub fn builder() -> CreateOAuthTokenBuilder<'a> {
CreateOAuthTokenBuilder::default()
}
}
impl<'a> Endpoint for CreateOAuthToken<'a> {
fn method(&self) -> Method {
Method::POST
}
fn endpoint(&self) -> Cow<'static, str> {
let mut base_url = format!("{}", &self.base_url).to_string();
if !base_url.ends_with('/') {
base_url += "/"
}
format!("{}oauth/token", &base_url).into()
}
fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, BodyError> {
let mut params = FormParams::default();
params
.push("grant_type", "password")
.push("username", &self.username)
.push("password", &self.password);
params.into_body()
}
}