Skip to main content

dhan_rs/types/
auth.rs

1#![allow(missing_docs)]
2//! Types for authentication endpoints.
3
4use serde::{Deserialize, Serialize};
5
6// ---------------------------------------------------------------------------
7// Token generation / renewal responses
8// ---------------------------------------------------------------------------
9
10/// Response from generating or consuming an access token.
11///
12/// Returned by:
13/// - `POST auth.dhan.co/app/generateAccessToken`
14/// - `POST auth.dhan.co/app/consumeApp-consent`
15/// - `POST auth.dhan.co/partner/consume-consent`
16/// - `GET /v2/RenewToken`
17#[derive(Debug, Clone, Deserialize)]
18#[serde(rename_all = "camelCase")]
19pub struct TokenResponse {
20    /// User-specific identification generated by Dhan.
21    pub dhan_client_id: String,
22    /// Name registered on Dhan.
23    #[serde(default)]
24    pub dhan_client_name: Option<String>,
25    /// Unique Client Code registered with Dhan.
26    #[serde(default)]
27    pub dhan_client_ucc: Option<String>,
28    /// DDPI status.
29    #[serde(default)]
30    pub given_power_of_attorney: Option<bool>,
31    /// Generated JWT access token.
32    pub access_token: String,
33    /// Token expiry time (ISO timestamp, IST).
34    #[serde(default)]
35    pub expiry_time: Option<String>,
36}
37
38// ---------------------------------------------------------------------------
39// Individual — API key consent flow
40// ---------------------------------------------------------------------------
41
42/// Response from generating an individual API-key consent.
43///
44/// Returned by `POST auth.dhan.co/app/generate-consent`.
45#[derive(Debug, Clone, Deserialize)]
46#[serde(rename_all = "camelCase")]
47pub struct AppConsentResponse {
48    /// Temporary session ID for the browser login step.
49    pub consent_app_id: String,
50    /// Status of the consent request.
51    pub consent_app_status: String,
52    /// Overall status field.
53    #[serde(default)]
54    pub status: Option<String>,
55}
56
57// ---------------------------------------------------------------------------
58// Partner consent flow
59// ---------------------------------------------------------------------------
60
61/// Response from generating a partner consent.
62///
63/// Returned by `POST auth.dhan.co/partner/generate-consent`.
64#[derive(Debug, Clone, Deserialize)]
65#[serde(rename_all = "camelCase")]
66pub struct PartnerConsentResponse {
67    /// Temporary session ID on the partner level.
68    pub consent_id: String,
69    /// Status of the consent request.
70    pub consent_status: String,
71}
72
73// ---------------------------------------------------------------------------
74// Static IP management
75// ---------------------------------------------------------------------------
76
77/// Request body for setting or modifying a static IP.
78#[derive(Debug, Clone, Serialize)]
79#[serde(rename_all = "camelCase")]
80pub struct SetIpRequest {
81    /// User-specific identification generated by Dhan.
82    pub dhan_client_id: String,
83    /// Static IP address (IPv4 or IPv6).
84    pub ip: String,
85    /// Whether this is the primary or secondary IP.
86    pub ip_flag: crate::types::IpFlag,
87}
88
89/// Response from `GET /v2/ip/getIP`.
90///
91/// Note: The API returns `primaryIP` / `secondaryIP` (uppercase `IP`),
92/// so we use explicit `#[serde(rename)]` instead of `rename_all`.
93#[derive(Debug, Clone, Deserialize)]
94pub struct IpInfo {
95    /// Currently set primary static IP.
96    #[serde(default, rename = "primaryIP")]
97    pub primary_ip: Option<String>,
98    /// Date from which the primary IP can be modified (YYYY-MM-DD).
99    #[serde(default, rename = "modifyDatePrimary")]
100    pub modify_date_primary: Option<String>,
101    /// Currently set secondary static IP.
102    #[serde(default, rename = "secondaryIP")]
103    pub secondary_ip: Option<String>,
104    /// Date from which the secondary IP can be modified (YYYY-MM-DD).
105    #[serde(default, rename = "modifyDateSecondary")]
106    pub modify_date_secondary: Option<String>,
107}
108
109/// Generic success response from set/modify IP.
110#[derive(Debug, Clone, Deserialize)]
111pub struct IpSetResponse {
112    pub message: String,
113    pub status: String,
114}