From c32f628c49f8ac82c0a7e79d9913be1c22659285 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 29 Dec 2022 19:05:27 +0100 Subject: [PATCH] Make Registered::complete() accept an AsRef This patch changes the signature of `Registered::complete` to accept an `AsRef`. This _should_ be backwards compatible to the old version. This change was implemented as it has the neat benefit that a user can implement a type that does not implement `Debug` or `Display`, but only `AsRef`. This can be done to ensure that the access code is not accidentially shown in log output, which might be pasted to some code forge for bug reporting. Signed-off-by: Matthias Beyer --- src/registration.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/registration.rs b/src/registration.rs index ce09cf2..129ca6d 100644 --- a/src/registration.rs +++ b/src/registration.rs @@ -336,11 +336,15 @@ impl Registered { /// Create an access token from the client id, client secret, and code /// provided by the authorization url. - pub async fn complete(&self, code: &str) -> Result { - let url = format!( + pub async fn complete(&self, code: C) -> Result + where + C: AsRef, + { + let url = + format!( "{}/oauth/token?client_id={}&client_secret={}&code={}&grant_type=authorization_code&\ redirect_uri={}", - self.base, self.client_id, self.client_secret, code, self.redirect + self.base, self.client_id, self.client_secret, code.as_ref(), self.redirect ); debug!(url = url; "completing registration"); let response = self.client.post(&url).send().await?;