diff options
author | ranfdev <ranfdev@gmail.com> | 2020-09-26 22:09:43 +0200 |
---|---|---|
committer | Paul Woolcock <paul@woolcock.us> | 2020-09-27 23:23:36 -0400 |
commit | 83587a10d2c7667360b2846a0601df2bc48c9677 (patch) | |
tree | b5054cc6c8052609573f5f84768ad54e51992bcb /src/registration.rs | |
parent | a8cbfad68f036355b717a8fa7e9f452c52ff00e7 (diff) |
Manually updated reqwest to 10.8 and url to 2.1
Diffstat (limited to 'src/registration.rs')
-rw-r--r-- | src/registration.rs | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/src/registration.rs b/src/registration.rs index 32bac61..5379e87 100644 --- a/src/registration.rs +++ b/src/registration.rs @@ -1,9 +1,8 @@ use std::borrow::Cow; -use reqwest::{Client, RequestBuilder, Response}; +use reqwest::blocking::{Client, RequestBuilder, Response}; use serde::Deserialize; use try_from::TryInto; -use url::percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET}; use crate::{ apps::{App, AppBuilder}, @@ -289,22 +288,16 @@ impl Registered { /// Returns the full url needed for authorisation. This needs to be opened /// in a browser. pub fn authorize_url(&self) -> Result<String> { - let scopes = format!("{}", self.scopes); - let scopes: String = utf8_percent_encode(&scopes, DEFAULT_ENCODE_SET).collect(); - let url = if self.force_login { - format!( - "{}/oauth/authorize?client_id={}&redirect_uri={}&scope={}&force_login=true&\ - response_type=code", - self.base, self.client_id, self.redirect, scopes, - ) - } else { - format!( - "{}/oauth/authorize?client_id={}&redirect_uri={}&scope={}&response_type=code", - self.base, self.client_id, self.redirect, scopes, - ) - }; + let mut url = url::Url::parse(&self.base)?.join("/oauth/authorize")?; + + url.query_pairs_mut() + .append_pair("client_id", &self.client_id) + .append_pair("redirect_uri", &self.redirect) + .append_pair("scope", &self.scopes.to_string()) + .append_pair("response_type", "code") + .append_pair("force_login", &self.force_login.to_string()); - Ok(url) + Ok(url.into_string()) } /// Create an access token from the client id, client secret, and code |