f2calv / CasCap.Apis.GooglePhotos

*unofficial* Google Photos REST API library for .NET projects.
MIT License
58 stars 10 forks source link

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

Open magicalpig opened 2 months ago

magicalpig commented 2 months ago

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

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.