Add stronger typing using the NewType pattern #38
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
NOTE: This is another breaking change that will be part of the 2.0.0 release.
This diff replaces weakly typed
String
s,Url
s, and other types with newtypes generated using the
NewType
pattern. Using stronger types hereshould avoid common mistakes (e.g., switching the order of the authorization
and endpoint URLs when instantiating a new
Client
).In addition to adding a
NewType
trait, this diff adds aNewSecretType
trait, which implements
Debug
in a way that redacts the secret. Thisbehavior avoids a common source of security bugs: logging secrets,
especially when errors occur. Unlike the
NewType
trait, theNewSecretType
does not implementDeref
. Instead, the secret mustbe explicitly extracted by calling the
secret
method.Finally, this PR resolves #28 by having the
authorize_url
method accept aclosure for generating a fresh CSRF token on each invocation. The token is
returned by the method as
#[must_use]
, which the caller should compareagainst the response sent by the authorization server to the redirect URI.
Note that
#[must_use]
currently has no effect in this context, but it shouldonce rust-lang/rust#39524 is resolved.