gw2api_rs/v2/
tokeninfo.rs

1use chrono::{DateTime, Utc};
2use serde::{Deserialize, Serialize};
3
4use crate::{Authentication, ClientExecutor, RequestBuilder};
5
6/// Details about an api token.
7#[derive(Clone, Debug, Serialize, Deserialize)]
8pub struct TokenInfo {
9    /// The unique id of the token.
10    pub id: String,
11    /// The name of the token defined by the user.
12    pub name: String,
13    /// All permissions granted to the token.
14    pub permissions: Vec<TokenPermission>,
15    /// The type of the token
16    #[serde(rename = "type")]
17    pub kind: TokenKind,
18    /// Expiration time of the token. Only avaliable on subtokens.
19    #[serde(default)]
20    pub expires_at: Option<DateTime<Utc>>,
21    /// Creation time of the token. Only avaliable on subtokens.
22    pub issued_at: Option<DateTime<Utc>>,
23    /// A list of urls the subtoken is restricted to. (optional)
24    pub urls: Option<Vec<String>>,
25}
26
27/// A token permission.
28#[derive(Clone, Debug, Serialize, Deserialize)]
29#[serde(rename_all = "lowercase")]
30pub enum TokenPermission {
31    Account,
32    Builds,
33    Characters,
34    Guilds,
35    Inventories,
36    Progression,
37    Pvp,
38    TradingPost,
39    Unlocks,
40    Wallet,
41}
42
43/// Type of an api token.
44#[derive(Clone, Debug, Serialize, Deserialize)]
45pub enum TokenKind {
46    ApiKey,
47    Subtoken,
48}
49
50impl TokenInfo {
51    pub fn get<C>(client: &C) -> C::Result
52    where
53        C: ClientExecutor<Self>,
54    {
55        client.send(RequestBuilder::new("/v2/tokeninfo").authenticated(Authentication::Required))
56    }
57}