saas-rs-sdk 0.6.0

The SaaS RS SDK
use crate::authentication::IdentityProviderHandler;
use async_trait::async_trait;
use http_api_isahc_client::IsahcClient;
use oauth2_amazon::{AmazonExtensionsBuilder, AmazonProviderWithWebServices, AmazonScope};
use oauth2_client::re_exports::{ClientId, ClientSecret, RedirectUri};
use oauth2_signin::web_app::{SigninFlow, SigninFlowHandleCallbackByQueryConfiguration, SigninFlowHandleCallbackRet};

pub use oauth2_amazon;

#[derive(Default)]
pub struct AmazonIdentityProviderHandler {}

#[async_trait]
impl IdentityProviderHandler for AmazonIdentityProviderHandler {
    async fn handle_callback(
        &self,
        client_id: ClientId,
        client_secret: ClientSecret,
        redirect_uri: RedirectUri,
        query: String,
    ) -> Result<SigninFlowHandleCallbackRet, Box<dyn std::error::Error>> {
        let client = IsahcClient::new()?;
        let provider = AmazonProviderWithWebServices::new(client_id, client_secret, redirect_uri, None)?;
        let scopes = vec![AmazonScope::Profile];
        let flow = SigninFlow::new(client, provider, scopes, AmazonExtensionsBuilder);
        let config = SigninFlowHandleCallbackByQueryConfiguration::new();
        Ok(flow.handle_callback_by_query(query, config).await)
    }
}