Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROTOTYPE: Auth separation #2405

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Conversation

jskeet
Copy link
Collaborator

@jskeet jskeet commented May 15, 2023

This wouldn't currently work at all, but highlights the dependencies from Google.Apis.Auth to Google.Apis and Google.Apis.Core.

The idea would be to create a new, very lightweight, dependency-free library of Google.Apis.Abstractions or something similar, which we'd use type forwarding for in the existing libraries, but depend on as our only dependency in Google.Apis.Auth.

The concrete code (as opposed to interface) that causes issues:

  • GoogleApiException: if we just change what ServiceCredential throws (for "Invalid OAuth scope or ID token audience provided") then we can remove this
  • Various back-off classes - we can probably hide most of these, just with code duplication between Google.Apis.Auth and Google.Apis
  • ApplicationContext - used for default loggers. We could use MS ILogger for Auth, which would remove this
  • ConfigurableMessageHandler / ConfigurableHttpClient - this is the big one. If we could find a way of using the MS IHttpClientFactory instead for auth code, that would be ideal. But IHttpClientFactory.CreateHttpClient returns ConfigurableHttpClient, which exposes ConfigurableMessageHandler :(

jskeet added 11 commits May 15, 2023 13:50
This as a *lot* of copies of dependencies - later commits will try to reduce this set.
This lets us remove BaseClientService and ClientServiceRequest.
(That should then let us remove a lot more dependencies.)
(There may be more.)

We can use a separate default auth-specific HttpClientFactory without nearly as many features.
We can hand-craft the serialization of these requests (and fix the responses, too)
This forces the user to specify a data store when creating a GoogleWebAuthorizationBroken, but that's probably okay.
We'll need a replacement "default serializer" but that doesn't need to be public.
@jskeet jskeet added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 15, 2023
@jskeet jskeet requested a review from amanda-tarafa May 15, 2023 14:02
@jskeet jskeet requested a review from a team as a code owner May 15, 2023 14:02
@jskeet
Copy link
Collaborator Author

jskeet commented May 15, 2023

The first commit basically copies everything Google.Apis.Auth needs (at all) into the project, then the rest of the commits remove them again, as far as we can...

/// <summary>
/// Asynchronously authorizes the specified user.
/// Requires user interaction; see <see cref="GoogleWebAuthorizationBroker"/> remarks for more details.
/// </summary>
/// <remarks>
/// In case no data store is specified, <see cref="Google.Apis.Util.Store.FileDataStore"/> will be used by
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I'm not convinced it's a good idea to not provide a data store by default. I think FileDataStore might be a good candidate to move to that very light common library.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly. I'd really hoped to get away without any concrete classes - and more importantly, FileDataStore uses NewtonsoftJsonSerializer.Instance :(

namespace Google.Apis.Auth.ExistingDependencies;

// The replacement for NewtonsoftJsonSerializer
internal class ReplacementSerializer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea to take a dependency on System.Text.Json or to just serialize/deserialize by hand?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no opinion on that at the moment :)

@@ -14,6 +14,9 @@
limitations under the License.
*/

// Note: the only reference to this is in ServiceAccountCredential. If we throw a different exception,
// e.g. InvalidOperationException, we could remove GoogleApiException, SingleError and RequestError.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With some of the initiatives around making errors more actionable I'd still expect things to move in the direction of using specific exception types with structured error messages, even for auth endpoints.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. We should work out what to do on that front then; but it's worth at least being aware that this is the only current usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Indicates a pull request not ready for merge, due to either quality or timing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants