refactor(oauth): Introduce AccountManagementUrlBuilder#4831
refactor(oauth): Introduce AccountManagementUrlBuilder#4831poljar merged 3 commits intomatrix-org:mainfrom
AccountManagementUrlBuilder#4831Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #4831 +/- ##
==========================================
+ Coverage 86.50% 86.52% +0.01%
==========================================
Files 297 297
Lines 34600 34607 +7
==========================================
+ Hits 29931 29942 +11
+ Misses 4669 4665 -4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
c9257d6 to
23f5d6f
Compare
It allows to reuse the URL for different actions more easily than having to call `OAuth::account_management_url` every time for a different action. It also adds a method with fallback if we want to ignore action serialization errors, to always present a URL. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
23f5d6f to
46da41e
Compare
|
Rebased on main to solve conflicts. |
poljar
left a comment
There was a problem hiding this comment.
Thanks, I left some small nits.
Could you clarify what you mean by:
AccountManagementUrlBuilder::build_or_ignore_action() also allows to ignore errors when serializing actions to always have a URL to use (although I'm not sure how to get errors there).
Do you mean that the serialization should be infallible?
| match url_builder.build() { | ||
| Ok(url) => Ok(Some(url.to_string())), | ||
| Err(e) => { | ||
| tracing::error!("Failed to build account management URL: {e}"); |
There was a problem hiding this comment.
Let's import error!() if it's used in multiple places.
There was a problem hiding this comment.
Changed. It was already imported 😛.
| /// Builder for the URL for accessing the account management capabilities, as | ||
| /// defined in [MSC4191]. | ||
| /// | ||
| /// # Arguments | ||
| /// This type can be instantiated with [`OAuth::account_management_url()`] and | ||
| /// [`OAuth::fetch_account_management_url()`]. | ||
| /// | ||
| /// * `account_management_uri` - The URL to access the issuer's account | ||
| /// management capabilities. | ||
| /// | ||
| /// * `action` - The action that the user wishes to take. | ||
| /// | ||
| /// # Returns | ||
| /// | ||
| /// A URL to be opened in a web browser where the end-user will be able to | ||
| /// access the account management capabilities of the issuer. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if serializing the action fails. | ||
| /// [`AccountManagementUrlBuilder::build()`] and | ||
| /// [`AccountManagementUrlBuilder::build_or_ignore_action()`] return a URL to be | ||
| /// opened in a web browser where the end-user will be able to access the | ||
| /// account management capabilities of the issuer. |
There was a problem hiding this comment.
Can we get an example here or on the method that returns this struct? There's now enough indirection for this to warrant some examples.
There was a problem hiding this comment.
I added an example.
It means that I am not sure when serialization in From what I understand, it should not be possible for it to fail though. The only variable input is the |
Ah ok, yeah it seems like it should™ be infallible to me as well. But let us be cautious here. |
|
Actually, there is a way to avoid the error if we don't use |
It's already imported. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
|
I got rid of potential errors by doing as I said. |
Ah neat. |
It allows to reuse the URL for different actions more easily than having to call
OAuth::account_management_urlevery time for a different action.AccountManagementUrlBuilder::build_or_ignore_action()also allows to ignore errors when serializing actions to always have a URL to use (although I'm not sure how to get errors there).