workos 1.0.0

Official Rust SDK for the WorkOS API
Documentation
// Code generated by oagen. DO NOT EDIT.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;

pub struct WidgetsApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateTokenParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: WidgetSessionToken,
}

impl CreateTokenParams {
    /// Construct a new `CreateTokenParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: WidgetSessionToken) -> Self {
        Self { body }
    }
}

impl<'a> WidgetsApi<'a> {
    /// Generate a widget token
    ///
    /// Generate a widget token scoped to an organization and user with the specified scopes.
    pub async fn create_token(
        &self,
        params: CreateTokenParams,
    ) -> Result<WidgetSessionTokenResponse, Error> {
        self.create_token_with_options(params, None).await
    }

    /// Variant of [`Self::create_token`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_token_with_options(
        &self,
        params: CreateTokenParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<WidgetSessionTokenResponse, Error> {
        let path = "/widgets/token".to_string();
        let method = http::Method::POST;
        self.client
            .request_with_body_opts(method, &path, &params, Some(&params.body), options)
            .await
    }
}