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

Option to omit client secret during authorization allowing for use of this library in a distributed app #170

Open
magicalpig opened this issue May 26, 2024 · 0 comments

Comments

@magicalpig
Copy link

magicalpig commented May 26, 2024

I'm far from an expert on the matters of OAuth and Google's APIs, but here's what I have gathered:

  • in a distributed app, such as one that would run on a user's desktop, the app's client secret for the Google API should not be included in the distribution because then it ceases to be a secret.
  • the recommendation for such distributed app is to use Authorization Code Flow with Proof Key for Code Exchange (PKCE). This flow does not require a client secret to be included in any authorization payloads
  • Google's dotnet library for authorization supports a PKCE flow. In fact, its AuthorizeAsync method has a "usePkce" argument that defaults to true. This seems to have been introduced in June 2023.

There's one caveat though: it seems when you request credentials for your app from the Google Cloud Console and you specify the app as a "Desktop app", Google still wants to see a client secret in the authorization request. However, specifying the app as "Universal Windows Platform (UWP)" -- even if the app has nothing to do with UWP -- opens the door for your app to omit the client secret and only send the client id. For example, this code successful authorizes a user

UserCredential credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
  new ClientSecrets { ClientId = _settings.GoogleAPIClientId },
  [ "https://www.googleapis.com/auth/photoslibrary.readonly" ],
  "local_user_X",
  CancellationToken.None
);

I believe this flow where the client secret is also now the recommendation for single-page apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant