Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 12 additions & 28 deletions aspnetcore/security/authentication/social/google-logins.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ uid: security/authentication/google-logins
---
# Google external login setup in ASP.NET Core

By [Valeriy Novytskyy](https://github.com/01binary) and [Rick Anderson](https://twitter.com/RickAndMSFT)
By [Valeriy Novytskyy](https://github.com/01binary), [Rick Anderson](https://twitter.com/RickAndMSFT) and [Sharaf Abacery](https://github.com/sharafabacery)

This tutorial shows you how to enable users to sign in with their Google account using the ASP.NET Core project created on the [previous page](xref:security/authentication/social/index).

## Create the Google OAuth 2.0 Client ID and secret

* Follow the guidance in [Integrating Google Sign-In into your web app](https://developers.google.com/identity/sign-in/web/sign-in) (Google documentation).
* Follow the guidance in [Integrating Google Sign-In into your web app](https://developers.google.com/identity/gsi/web/guides/overview) (Google documentation)
* Go to [Google API & Services](https://console.cloud.google.com/apis).
* A **Project** must exist first, you may have to create one. Once a project is selected, enter the **Dashboard**.

Expand Down Expand Up @@ -53,37 +53,21 @@ You can manage your API credentials and usage in the [API Console](https://conso

## Configure Google authentication

Add the [`Microsoft.AspNetCore.Authentication.Google`](https://www.nuget.org/packages/Microsoft.AspNetCore.Authentication.Google) NuGet package to the app.

:::moniker range="< aspnetcore-6.0"

Add the Authentication service to the `Startup.ConfigureServices`:

[!code-csharp[](~/security/authentication/social/social-code/3.x/StartupGoogle3x.cs?highlight=11-19)]

:::moniker-end

:::moniker range=">= aspnetcore-6.0"

Add the Authentication service to the `Program`:

[!code-csharp[](~/security/authentication/social/social-code/6.x/ProgramGoogle.cs)]

:::moniker-end
* Add the [`Google.Apis.Auth.AspNetCore3`](https://www.nuget.org/packages/Google.Apis.Auth.AspNetCore3) NuGet package to the app.
* Add the Authentication service to the `program.cs`:
* Follow [`Add Authtication for asp.net app`](https://developers.google.com/api-client-library/dotnet/guide/aaa_oauth#configure-your-application-to-use-google.apis.auth.aspnetcore3)

[!INCLUDE [default settings configuration](includes/default-settings2-2.md)]

## Sign in with Google
* Get a link to the libary at [google developer library link ](https://developers.google.com/identity/gsi/web/guides/client-library) to get link of library.
* Then go to [google developer button genration ](https://developers.google.com/identity/gsi/web/tools/configurator)
* Setup your Controller to match with ` data-login_uri="{HostName}/{ControllerName}/{actionName}" ` attrbute because after success login it will forward you to that link.
* Create a controller and action that takes one argument `string credential`, which is returned by Google upon completing the login process.
* Verify the `credential` using the following line of code:
`GoogleJsonWebSignature.Payload payload = await GoogleJsonWebSignature.ValidateAsync(credential);`
* This will retrieve the available information about the logged-in user, which could then be stored in a database.

* Run the app and select **Log in**. An option to sign in with Google appears.
* Select the **Google** button, which redirects to Google for authentication.
* After entering your Google credentials, you are redirected back to the web site.

[!INCLUDE[Forward request information when behind a proxy or load balancer section](includes/forwarded-headers-middleware.md)]

[!INCLUDE[](includes/chain-auth-providers.md)]

For more information on configuration options supported by Google authentication, see the <xref:Microsoft.AspNetCore.Authentication.Google.GoogleOptions> API reference . This can be used to request different information about the user.

## Change the default callback URI

Expand Down
31 changes: 11 additions & 20 deletions aspnetcore/tutorials/first-mongo-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ uid: tutorials/first-mongo-app

By [Pratik Khandelwal](https://twitter.com/K2Prk) and [Scott Addie](https://twitter.com/Scott_Addie)

:::moniker range=">= aspnetcore-8.0"
:::moniker range=">= aspnetcore-9.0"

This tutorial creates a web API that runs Create, Read, Update, and Delete (CRUD) operations on a [MongoDB](https://www.mongodb.com/what-is-mongodb) NoSQL database.

Expand All @@ -35,15 +35,11 @@ In this tutorial, you learn how to:

# [Visual Studio](#tab/visual-studio)

[!INCLUDE[](~/includes/net-prereqs-vs-8.0.md)]
[!INCLUDE[](~/includes/net-prereqs-vs-9.0.md)]

# [Visual Studio Code](#tab/visual-studio-code)

[!INCLUDE[](~/includes/net-prereqs-vsc-8.0.md)]

# [Visual Studio for Mac](#tab/visual-studio-mac)

[!INCLUDE[](~/includes/net-prereqs-mac-8.0.md)]
[!INCLUDE[](~/includes/net-prereqs-vsc-9.0.md)]

---

Expand Down Expand Up @@ -151,7 +147,11 @@ Use the previously installed MongoDB Shell in the following steps to create a da
1. Go to **File** > **New** > **Project**.
1. Select the **ASP.NET Core Web API** project type, and select **Next**.
1. Name the project *BookStoreApi*, and select **Next**.
1. Select the **.NET 8.0 (Long Term support)** framework and select **Create**.
1. In the **Additional information** dialog:
* Confirm the **Framework** is **.NET 9.0 (Standard Term Support)**.
* Confirm the checkbox for **Use controllers** is checked.
* Confirm the checkbox for **Enable OpenAPI support** is checked.
* Select **Create**.
1. In the **Package Manager Console** window, navigate to the project root. Run the following command to install the .NET driver for MongoDB:

```powershell
Expand All @@ -163,7 +163,7 @@ Use the previously installed MongoDB Shell in the following steps to create a da
1. Run the following commands in a command shell:

```dotnetcli
dotnet new webapi -o BookStoreApi
dotnet new webapi -o BookStoreApi --use-controllers
code BookStoreApi
```

Expand All @@ -176,17 +176,6 @@ Use the previously installed MongoDB Shell in the following steps to create a da
dotnet add package MongoDB.Driver
```

# [Visual Studio for Mac](#tab/visual-studio-mac)

1. Select **File** > **New Project...**.
1. Select **Web and Console** > **App** from the sidebar.
1. Select the **ASP.NET Core** > **API** C# project template, and select **Next**.
1. Select **.NET 8.0** from the **Target Framework** drop-down list, and select **Next**.
1. Enter *BookStoreApi* for the **Project Name**, and select **Create**.
1. In the **Solution** pad, right-click the project's **Dependencies** node and select **Manage NuGet Packages**.
1. Enter *MongoDB.Driver* in the search box, select the *MongoDB.Driver* package, and select **Add Package**.
1. Select the **Accept** button in the **License Acceptance** dialog.

---

## Add an entity model
Expand Down Expand Up @@ -352,6 +341,8 @@ To satisfy the preceding requirements, make the following changes:

:::moniker-end

[!INCLUDE[](~/tutorials/first-mongo-app/includes/first-mongo-app8.md)]

[!INCLUDE[](~/tutorials/first-mongo-app/includes/first-mongo-app7.md)]

[!INCLUDE[](~/tutorials/first-mongo-app/includes/first-mongo-app6.md)]
Expand Down
Loading
Loading