-
Notifications
You must be signed in to change notification settings - Fork 10
[TIC-365] Add create_access_token request
#15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4fe0b76
feat(create_access_token): create access token service, request/respo…
itailevi98 330f22c
feat(create_access_token): add AccessTokenService, errors for errored…
itailevi98 86a4a2e
feat(auth): add access_token function to auth
itailevi98 c09d467
chore: add comment for what the api is
itailevi98 ee7cb17
docs(access_token): add docs for new access_token api, create_access_…
itailevi98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # \AccessTokenServiceApi | ||
|
|
||
| All URIs are relative to _http://localhost_ | ||
|
|
||
| | Method | HTTP request | Description | | ||
| | ----------------------------------------------------------------------- | ------------------------------------- | ----------- | | ||
| | [**create_access_Token**](AccessTokenServiceApi.md#create_access_token) | **POST** /api/backend/v1/access_token | | ||
|
|
||
| ## create_access_Token | ||
|
|
||
| > crate::models::CreateAccessTokenResponse create_access_token(create_access_token_params) | ||
|
|
||
| ### Parameters | ||
|
|
||
| | Name | Type | Description | Notes | | ||
| | -------------------------- | -------------------------------------------------------------------------- | ----------- | ----- | | ||
| | create_access_token_params | [**crate::models::CreateAccessTokenRequest**](CreateAccessTokenRequest.md) | | | | ||
|
|
||
| ### Return type | ||
|
|
||
| [**crate::models::CreateAccessTokenResponse**](CreateAccessTokenResponse.md) | ||
|
|
||
| ### Authorization | ||
|
|
||
| [BearerAuth](../README.md#BearerAuth) | ||
|
|
||
| ### HTTP request headers | ||
|
|
||
| - **Content-Type**: Not defined | ||
| - **Accept**: application/json | ||
|
|
||
| [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # CreateAccessTokenRequest | ||
|
|
||
| ## Properties | ||
|
|
||
| | Name | Type | Description | Notes | | ||
| | --------------------------- | -------------------- | ----------- | ----- | | ||
| | **user_id** | **String** | | | ||
| | **duration_in_minutes** | **u64** | | | ||
| | **active_org_id** | **Option\<String\>** | | | ||
| | **with_active_org_support** | **bool** | | | ||
|
|
||
| [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # CreateAccessTokenResponse | ||
|
|
||
| ## Properties | ||
|
|
||
| | Name | Type | Description | Notes | | ||
| | ---------------- | ---------- | ----------- | ----- | | ||
| | **access_token** | **String** | | | ||
|
|
||
| [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| use reqwest; | ||
|
|
||
| use crate::apis::ResponseContent; | ||
| use super::{Error, configuration}; | ||
|
|
||
| /// struct for passing parameters to the method [`create_access_token`] | ||
| #[derive(Clone, Debug, Default)] | ||
| pub struct CreateAccessTokenParams { | ||
| pub create_access_token_request: crate::models::CreateAccessTokenRequest | ||
| } | ||
|
|
||
|
|
||
|
|
||
| /// struct for typed errors of method [`create_access_token`] | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| #[serde(untagged)] | ||
| pub enum CreateAccessTokenError { | ||
| Status400(crate::models::BadCreateAccessTokenError), | ||
| Status401(serde_json::Value), | ||
| Status404(serde_json::Value), | ||
| UnknownValue(serde_json::Value), | ||
| } | ||
|
|
||
|
|
||
| pub async fn create_access_token(configuration: &configuration::Configuration, params: CreateAccessTokenParams) -> Result<crate::models::CreateAccessTokenResponse, Error<CreateAccessTokenError>> { | ||
| let local_var_configuration = configuration; | ||
|
|
||
| // unbox the parameters | ||
| let create_access_token_request = params.create_access_token_request; | ||
|
|
||
| let local_var_client = &local_var_configuration.client; | ||
|
|
||
| let local_var_uri_str = format!("{}/api/backend/v1/access_token", local_var_configuration.base_path); | ||
| let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str()); | ||
|
|
||
| if let Some(ref local_var_user_agent) = local_var_configuration.user_agent { | ||
| local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone()); | ||
| } | ||
| if let Some(ref local_var_token) = local_var_configuration.bearer_access_token { | ||
| local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned()); | ||
| }; | ||
| local_var_req_builder = local_var_req_builder.json(&create_access_token_request); | ||
|
|
||
| let local_var_req = local_var_req_builder.build()?; | ||
| let local_var_resp = local_var_client.execute(local_var_req).await?; | ||
|
|
||
| let local_var_status = local_var_resp.status(); | ||
| let local_var_content = local_var_resp.text().await?; | ||
|
|
||
| if !local_var_status.is_client_error() && !local_var_status.is_server_error() { | ||
| serde_json::from_str(&local_var_content).map_err(Error::from) | ||
| } else { | ||
| let local_var_entity: Option<CreateAccessTokenError> = serde_json::from_str(&local_var_content).ok(); | ||
| let local_var_error: ResponseContent<CreateAccessTokenError> = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity }; | ||
| Err(Error::ResponseError(local_var_error)) | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
|
|
||
| #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] | ||
| pub struct BadCreateAccessTokenError { | ||
| #[serde(rename = "active_org_id", skip_serializing_if = "Option::is_none")] | ||
| pub active_org_id: Option<Vec<String>>, | ||
| #[serde(rename = "user_id", skip_serializing_if = "Option::is_none")] | ||
| pub user_id: Option<Vec<String>>, | ||
| } | ||
|
|
||
| impl BadCreateAccessTokenError { | ||
| pub fn new() -> BadCreateAccessTokenError { | ||
| BadCreateAccessTokenError { | ||
| active_org_id: None, | ||
| user_id: None, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] | ||
| pub struct CreateAccessTokenRequest { | ||
| #[serde(rename = "user_id")] | ||
| pub user_id: String, | ||
| #[serde(rename = "duration_in_minutes")] | ||
| pub duration_in_minutes: u64, | ||
| #[serde(rename = "active_org_id", skip_serializing_if = "Option::is_none")] | ||
| pub active_org_id: Option<String>, | ||
| #[serde(rename = "with_active_org_support")] | ||
| pub with_active_org_support: bool, | ||
| } | ||
|
|
||
| impl CreateAccessTokenRequest { | ||
| pub fn new(user_id: String, duration_in_minutes: u64, with_active_org_support: bool) -> CreateAccessTokenRequest { | ||
| CreateAccessTokenRequest { | ||
| user_id, | ||
| active_org_id: None, | ||
| duration_in_minutes, | ||
| with_active_org_support, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #[derive(Clone, Debug, PartialEq, Default, Serialize, Deserialize)] | ||
| pub struct CreateAccessTokenResponse { | ||
| pub access_token: String, | ||
| } | ||
|
|
||
| impl CreateAccessTokenResponse { | ||
| pub fn new(access_token: String) -> Self { | ||
| CreateAccessTokenResponse { | ||
| access_token, | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| use crate::apis::access_token_service_api::CreateAccessTokenParams; | ||
| use crate::apis::configuration::Configuration; | ||
|
|
||
| use crate::models::CreateAccessTokenResponse; | ||
| use crate::propelauth::errors::CreateAccessTokenError; | ||
| use crate::propelauth::helpers::{is_valid_id, map_autogenerated_error}; | ||
|
|
||
| pub struct AccessTokenService<'a> { | ||
| pub(crate) config: &'a Configuration, | ||
| } | ||
|
|
||
| impl AccessTokenService<'_> { | ||
| pub async fn create_access_token(&self, params: CreateAccessTokenParams) -> Result<CreateAccessTokenResponse, CreateAccessTokenError> { | ||
| if !is_valid_id(¶ms.create_access_token_request.user_id) { | ||
| return Err(CreateAccessTokenError::NotFound); | ||
| } | ||
|
|
||
| crate::apis::access_token_service_api::create_access_token(&self.config, params) | ||
| .await | ||
| .map_err(|err| { | ||
| map_autogenerated_error( | ||
| err, | ||
| CreateAccessTokenError::UnexpectedException, | ||
| |status_code, err_entity| match (status_code.as_u16(), err_entity) { | ||
| ( | ||
| _, | ||
| Some(crate::apis::access_token_service_api::CreateAccessTokenError::Status400( | ||
| bad_request, | ||
| )), | ||
| ) => CreateAccessTokenError::BadRequest(bad_request), | ||
| (401, _) => CreateAccessTokenError::InvalidApiKey, | ||
| (404, _) => CreateAccessTokenError::NotFound, | ||
| _ => CreateAccessTokenError::UnexpectedException, | ||
| }, | ||
| ) | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,4 @@ pub mod org; | |
| pub mod token; | ||
| pub mod token_models; | ||
| pub mod user; | ||
| pub mod access_token; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.