oauth2
oauth2 copied to clipboard
Redact sensitive struct fields on inspect
Hi,
Thanks for this great library.
Noticed these fields end up on our app's logs and/or error tracking reports in cases like e.g. MatchError: no match of right hand side value: %OAuth2.Client{..., client_secret: "<secret>", ...} when having match errors when doing stuff like
%{
...
} = oauth2_client
We temporarily fixed this on our app's end by writing
defimpl Inspect, for: OAuth2.Client do
def inspect(%OAuth2.Client{} = client, opts) do
client
|> Map.replace(:client_secret, "[REDACTED]")
|> Inspect.Any.inspect(opts)
end
end
defimpl Inspect, for: OAuth2.AccessToken do
def inspect(%OAuth2.AccessToken{} = client, opts) do
client
|> Map.replace(:access_token, "[REDACTED]")
|> Map.replace(:refresh_token, "[REDACTED]")
|> Inspect.Any.inspect(opts)
end
end
But maybe you wanted to consider adding it to the package?
Thanks.