use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(test, derive(Default))]
pub struct Oauth2Token {
#[serde(rename = "access_token")]
pub access_token: String,
#[serde(rename = "token_type")]
pub token_type: String,
#[serde(rename = "expires_in")]
pub expires_in: i64,
#[serde(rename = "refresh_token")]
pub refresh_token: String,
#[serde(rename = "scope")]
pub scope: String,
#[serde(rename = "authorization_details")]
#[serde(skip_serializing_if = "Option::is_none")]
pub authorization_details: Option<String>,
#[serde(rename = "id_token")]
#[serde(skip_serializing_if = "Option::is_none")]
pub id_token: Option<String>,
}
impl Oauth2Token {
pub fn access_token(&self) -> &String {
&self.access_token
}
pub fn token_type(&self) -> &String {
&self.token_type
}
pub fn expires_in(&self) -> &i64 {
&self.expires_in
}
pub fn refresh_token(&self) -> &String {
&self.refresh_token
}
pub fn scope(&self) -> &String {
&self.scope
}
pub fn set_authorization_details(mut self, authorization_details: String) -> Self {
self.authorization_details = Some(authorization_details);
self
}
pub fn authorization_details(&self) -> Option<&String> {
self.authorization_details.as_ref()
}
pub fn set_id_token(mut self, id_token: String) -> Self {
self.id_token = Some(id_token);
self
}
pub fn id_token(&self) -> Option<&String> {
self.id_token.as_ref()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_oauth2_token_creation() {
let _model = <Oauth2Token as Default>::default();
let _ = _model.access_token();
let _ = _model.token_type();
let _ = _model.expires_in();
let _ = _model.refresh_token();
let _ = _model.scope();
}
#[test]
fn test_oauth2_token_serialization() {
let model = <Oauth2Token as Default>::default();
let json = serde_json::to_string(&model);
assert!(json.is_ok());
let deserialized: Result<Oauth2Token, _> = serde_json::from_str(&json.unwrap());
assert!(deserialized.is_ok());
}
}