openidconnect-rs icon indicating copy to clipboard operation
openidconnect-rs copied to clipboard

FR: Conversion Trait implementation for configuration types

Open mhutter opened this issue 7 months ago • 2 comments

Feature Request

Implement std::str::FromStr or From<String> for commonly used configuration types:

  • IssuerUrl
  • ClientId
  • ClientSecret
  • RedirectUrl

(maybe more?)

Use Case/Context

This would make it much more ergonomic to load those values from the environment or config files, e.g. when using frameworks like envconfig or serde.

mhutter avatar Apr 22 '25 16:04 mhutter

Hi @ramosbugs, I want to implement this, but before I start investing time, is this something you'd be willing to merge?

(Edit: of course here and in https://github.com/ramosbugs/oauth2-rs)

mhutter avatar Apr 22 '25 16:04 mhutter

Looking at the code, it might make sense to implement this directly in the new_type! and new_url_type! macros.

mhutter avatar Apr 22 '25 16:04 mhutter

the NewType pattern used in these two crates intentionally omits such convenience interfaces in favor of explicitness for the reasons outlined here: https://github.com/ramosbugs/oauth2-rs/issues/112#issuecomment-675801545

This would make it much more ergonomic to load those values from the environment or config files, e.g. when using frameworks like envconfig or serde.

the types do implement Serialize and Deserialize for serde. for other use cases, the code will need to explicitly cast lower-level strings to these higher-level abstractions.

ramosbugs avatar Jul 06 '25 22:07 ramosbugs