The Google.Apis.Auth.AspNetCore3 contains a Google-specific OpenIdConnect auth handler. It supports incremental auth, and defines an injectable IGoogleAuthProvider to supply Google credentials.
Google.Apis.Auth.AspNetCore3.IntegrationTests is a standard ASP.NET Core 3 application that shows how to configure and use the main features of Google.Apis.Auth.AspNetCore3.
First you need to create a Google Cloud project if you don't have one already. Follow these instructions to do so. This will be the project the app is identified with.
The app uses the Google Drive and Calendar APIs. These need to be enabled in your GCP project. To enable the APIs, follow these instructions.
These credentials are the ones that identify your app to Google. Follow these instructions to create authorization credentials and download the client_secrets.json file. Two highlights:
- Notice that the credentials' type must be Web application.
- For running this app, the only redirect URI you need to add is https://localhost:5001/signin-oidc
- Set
TEST_WEB_CLIENT_SECRET_FILENAME
to the path of the client_secrets.json file you downloaded on the previous step.
You need ASP.NET Core 3.1 which you can download and install here. Alternatively you can use Visual Studio 2019.
- Use Git to clone this repo locally.
- On the command line, go to the location where you cloned the repo.
- An then go to google-api-dotnet-client/Src/Support/Google.Apis.Auth.AspNetCore3.IntegrationTests.
- Run the app with
dotnet run
. - The local web server should start and a browser window should open showing this app's Index page.
- There are several links on the Index page that will allow you to test Google.Apis.Auth.AspNetCore3 features. All the links have an acompanying explanation of what they do.
Google.Apis.Auth.AspNetCore3.IntegrationTests is a standard ASP.NET Core 3 app.
- In
Startup.cs
you can see how to configure Google.Apis.Auth.AspNetCore3. - In
Controllers/HomeControllers.cs
you can see the code you need to write for each of the features showcased by the app. - In
Views/Home/
you'll find all the cshtml files that make up the app's UI. These are mostly HTML with a little code to help format the information they show. ClientInfo.cs
contains helper code to load the OAuth credential client ID and secret from the client_secrets.json file you downloaded from GCP. In your own app, you can use this approach or you can store your client ID and secret in any other secure manner of your choosing.