feature/gresiq-v1
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | use { |
| 2 | crate::client_credentials::{ClientCredentials, base_url_builder as tenant_base_url_builder}, |
| 3 | reqwest::{Client, StatusCode}, |
| 4 | smbcloud_model::error_codes::{ErrorCode, ErrorResponse}, |
| 5 | smbcloud_network::environment::Environment, |
| 6 | smbcloud_networking::{ |
| 7 | constants::PATH_USERS_SIGN_OUT, smb_base_url_builder, smb_client::SmbClient, |
| 8 | }, |
| 9 | }; |
| 10 | |
| 11 | pub async fn logout( |
| 12 | env: Environment, |
| 13 | client: (&SmbClient, &str), |
| 14 | access_token: String, |
| 15 | ) -> Result<(), ErrorResponse> { |
| 16 | let response = match Client::new() |
| 17 | .delete(build_smb_logout_url(env, client)) |
| 18 | .header("Authorization", access_token) |
| 19 | .header("Accept", "application/json") |
| 20 | .header("Content-Type", "application/x-www-form-urlencoded") |
| 21 | .send() |
| 22 | .await |
| 23 | { |
| 24 | Ok(response) => response, |
| 25 | Err(_) => { |
| 26 | return Err(ErrorResponse::Error { |
| 27 | error_code: ErrorCode::Unknown, |
| 28 | message: ErrorCode::Unknown.message(None).to_string(), |
| 29 | }); |
| 30 | } |
| 31 | }; |
| 32 | |
| 33 | match response.status() { |
| 34 | StatusCode::OK => Ok(()), |
| 35 | _ => Err(ErrorResponse::Error { |
| 36 | error_code: ErrorCode::Unauthorized, |
| 37 | message: ErrorCode::Unauthorized.message(None).to_string(), |
| 38 | }), |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | pub async fn logout_with_client( |
| 43 | env: Environment, |
| 44 | client: ClientCredentials<'_>, |
| 45 | access_token: String, |
| 46 | ) -> Result<(), ErrorResponse> { |
| 47 | let response = match Client::new() |
| 48 | .delete(build_logout_url_with_client(env, client)) |
| 49 | .header("Authorization", access_token) |
| 50 | .header("Accept", "application/json") |
| 51 | .header("Content-Type", "application/x-www-form-urlencoded") |
| 52 | .send() |
| 53 | .await |
| 54 | { |
| 55 | Ok(response) => response, |
| 56 | Err(_) => { |
| 57 | return Err(ErrorResponse::Error { |
| 58 | error_code: ErrorCode::Unknown, |
| 59 | message: ErrorCode::Unknown.message(None).to_string(), |
| 60 | }); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | match response.status() { |
| 65 | StatusCode::OK => Ok(()), |
| 66 | _ => Err(ErrorResponse::Error { |
| 67 | error_code: ErrorCode::Unauthorized, |
| 68 | message: ErrorCode::Unauthorized.message(None).to_string(), |
| 69 | }), |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | fn build_smb_logout_url(env: Environment, client: (&SmbClient, &str)) -> String { |
| 74 | let mut url_builder = smb_base_url_builder(env, client); |
| 75 | url_builder.add_route(PATH_USERS_SIGN_OUT); |
| 76 | url_builder.build() |
| 77 | } |
| 78 | |
| 79 | fn build_logout_url_with_client(env: Environment, client: ClientCredentials<'_>) -> String { |
| 80 | let mut url_builder = tenant_base_url_builder(env, client); |
| 81 | url_builder.add_route("v1/client/users/sign_out"); |
| 82 | url_builder.build() |
| 83 | } |