use std::path::PathBuf;
use oauth2::Scope;
use super::oauth2::Oauth2Authent;
pub(crate) struct Oauth2AuthentBuilder {
token_path: Option<String>,
user_agent: String,
scopes: Vec<Scope>,
verify_url: String, auth_url: String, token_url: String, callback_url: String, client_id: String,
client_secret: String,
}
impl Oauth2AuthentBuilder {
pub fn build(self) -> Oauth2Authent {
Oauth2Authent {
token_path: self.token_path.map(|t| PathBuf::from(&t)),
authent_token: None,
user_agent: self.user_agent,
verify_url: self.verify_url,
auth_url: self.auth_url,
token_url: self.token_url,
callback_url: self.callback_url,
client_id: self.client_id,
client_secret: self.client_secret,
scopes: self.scopes,
}
}
pub fn with_scopes(mut self, scopes: Vec<&str>) -> Self {
self.scopes = scopes.iter().map(|s| Scope::new(s.to_string())).collect();
self
}
pub fn with_token_path(mut self, path: &str) -> Self {
self.token_path = Some(path.to_string());
self
}
pub fn new(client_id: String, client_secret: String) -> Oauth2AuthentBuilder {
Oauth2AuthentBuilder {
token_path: None,
user_agent: "default eve-cli".to_string(),
scopes: vec![Scope::new("publicData".to_string())],
verify_url: "https://login.eveonline.com/oauth/verify".to_string(),
auth_url: "https://login.eveonline.com/v2/oauth/authorize".to_string(),
token_url: "https://login.eveonline.com/v2/oauth/token".to_string(),
callback_url: "http://localhost:8569/callback".to_string(),
client_id,
client_secret,
}
}
}