# Social Login

- [Introduction](#introduction)
- [Configuration](#configuration)
    - [Google](#google)
    - [GitHub](#github)
    - [Microsoft](#microsoft)
- [Preparing your users table](#preparing-your-users-table)
- [Authentication](#authentication)
    - [Routing](#routing)
    - [Logging the user in](#logging-the-user-in)
    - [Linking existing accounts](#linking-existing-accounts)
    - [When the user cancels](#when-the-user-cancels)
    - [Access scopes and optional parameters](#access-scopes-and-optional-parameters)
- [Retrieving user details](#retrieving-user-details)
    - [Restricting logins to your organization](#restricting-logins-to-your-organization)
- [Adding providers](#adding-providers)
    - [Reading profiles from the provider's API](#reading-profiles-from-the-providers-api)
- [Testing](#testing)

<a name="introduction"></a>

## Introduction


初めてアプリケーションを使う人は、またパスワードを作ることを避けたいかもしれません。たとえば **Googleで続ける** ボタンがあれば、既存のアカウントで登録し、次回からワンクリックでログインできます。`auth/social` パッケージはGoogle、GitHub、Microsoftアカウントでのログインを提供し、GitLab、Okta、Keycloakなどを [add other providers](#adding-providers) できます。ユーザーをプロバイダへ送り、戻ってきた応答を検証して、ID、名前、メールアドレスを提供します。保存する情報を決め、他のログインと同じように [`auth.Login`](/ja/go/docs/authentication#logging-in-a-user-you-already-have) でログインさせます。


ソーシャルログインは各ログインの状態を [session](/ja/go/docs/session) に保存するため、`web` ミドルウェアグループで実行される `routes/web.go` にルートを追加してください。

<a name="configuration"></a>

## Configuration


ユーザーがプロバイダでログインするには、先にその開発者コンソールで OAuth アプリケーションを作成します。発行されたクライアント ID とクライアントシークレットを `.env` に追加してください。アプリケーションで提供するプロバイダだけを追加します。

```ini
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

MICROSOFT_CLIENT_ID=
MICROSOFT_CLIENT_SECRET=
```


アプリケーションの作成時、コンソールはコールバックURLも求めます。ユーザーがアプリケーションを承認した後にプロバイダが戻す先です。Laravelはアプリケーションのホスト上の `/auth/{provider}/callback`、たとえば `https://example.com/auth/google/callback` を想定します。ローカル開発用に `http://localhost:8000/auth/google/callback` も登録してください。


別のコールバックURLを使うには、`GOOGLE_REDIRECT_URI`、`GITHUB_REDIRECT_URI`、`MICROSOFT_REDIRECT_URI` にプロバイダへ登録したURLを設定し、[callback route](#routing) に同じパスを指定します。パスのみの場合は、リクエストのホストを基準に解決します。

```ini
GOOGLE_REDIRECT_URI=/login/google/callback
```

<a name="google"></a>

### Google


[Google Cloud console](https://console.cloud.google.com/apis/credentials) で、種類が **ウェブ アプリケーション** の **OAuth クライアント ID** を作成し、**承認済みのリダイレクト URI** にコールバック URL を追加します。

<a name="github"></a>

### GitHub


GitHub の設定で **開発者設定**、**OAuth アプリ** の順に開き、新しいアプリケーションを作成します。**認可コールバック URL** にコールバック URL を指定します。


組織がGitHub Enterprise Serverを使っている場合は、そのインスタンスでOAuthアプリを作成し、`GITHUB_URL` にベースURLを設定してください。Laravelはログインをそのサーバーへリダイレクトし、`/api/v3` からユーザープロフィールを読み取ります。

```ini
GITHUB_URL=https://github.example.com
```

<a name="microsoft"></a>

### Microsoft


Microsoft Entra 管理センターで **アプリの登録** を開き、新しいアプリケーションを登録します。コールバック URL を **Web** リダイレクト URI として追加し、**証明書とシークレット** でクライアントシークレットを作成します。


選択する **サポートされているアカウントの種類** は `MICROSOFT_TENANT` と一致させる必要があります。

| `MICROSOFT_TENANT` | ログインできるユーザー |
| --- | --- |
| `common` | 職場、学校、個人の Microsoft アカウントを持つ全員。デフォルト |
| `organizations` | 職場または学校のアカウントを持つ全員 |
| `consumers` | 個人の Microsoft アカウントを持つ全員 |
| テナント ID | その組織のユーザーのみ |


**トークン構成**で、IDトークンに省略可能なクレーム `xms_edov` を追加してください。会社や学校のアカウントのメールアドレスがログインする本人のものかをLaravelに伝えます。このクレームがないと未確認として扱われ、既存ユーザーへ [link the accounts](#linking-existing-accounts) できません。個人のMicrosoftアカウントには不要です。

<a name="preparing-your-users-table"></a>

## Preparing your users table


usersテーブルには、各ユーザーに属するプロバイダアカウントを記録する必要があるため、`provider` と `provider_id` カラムを追加します。プロバイダ経由で登録したユーザーにはパスワードがないため、`password` カラムもnullableにします。次のマイグレーションは、新規アプリケーションで作成される `users` テーブルを変更します。

```go
// database/migrations/2026_11_12_000000_add_social_login_to_users_table.go
package migrations

import (
	"context"

	"go.laravel.com/schema"
)

func addSocialLoginToUsersTable(ctx context.Context) error {
	return schema.Alter(ctx, "users", func(table *schema.Blueprint) {
		table.String("password").Nullable().Change()
		table.String("provider").Nullable()
		table.String("provider_id").Nullable()

		table.Unique("provider", "provider_id")
	})
}
```


`database/migrations/migrations.go` の `All` で、テーブルを作成するマイグレーションの後に追加します。

```go
{Name: "2026_11_12_000000_add_social_login_to_users_table", Run: addSocialLoginToUsersTable},
```


次に `User` モデルへフィールドを追加し、パスワードをポインタにします。パスワードがないユーザーでは `nil` になります。`social.Provider` フィールドは `google` や `github` などのプロバイダ名を保存します。[password reset](/ja/go/docs/passwords) メールに必要な `MailAddress` など、既にモデルへ追加したメソッドは維持してください。

```go
// models/user.go
package models

import (
	"time"

	"go.laravel.com/auth/social"
)

type User struct {
	ID              int64            `json:"id"`
	Name            string           `json:"name"`
	Email           string           `json:"email"`
	EmailVerifiedAt *time.Time       `json:"email_verified_at"`
	Password        *string          `json:"-"`
	RememberToken   *string          `json:"-"`
	Provider        *social.Provider `json:"provider"`
	ProviderID      *string          `json:"-"`
	CreatedAt       time.Time        `json:"created_at"`
	UpdatedAt       time.Time        `json:"updated_at"`
}
```


パスワードを持つユーザーには、引き続きログインフォームが使えます。プロバイダ経由で登録したユーザーは、[password reset](/ja/go/docs/passwords) でパスワードを設定するまでフォームからログインできません。

<a name="authentication"></a>

## Authentication

<a name="routing"></a>

### Routing


プロバイダでログインするには、ユーザーをプロバイダへ送るルートと、戻ってきたユーザーを受け取るルートが必要です。`{provider}` パラメータにより、1組のルートですべてのプロバイダを扱えます。`routes/web.go` で、他のゲスト専用ページとともに [`RedirectIfAuthenticated`](/ja/go/docs/authentication#pages-for-guests-only) グループへ追加してください。

```go
// routes/web.go
package routes

import (
	"go.laravel.com/auth"
	"go.laravel.com/config"
	"go.laravel.com/routing"

	"app/handlers/sociallogin"
)

func Web(route *routing.Router, cfg *config.Config) {
	route.Middleware(auth.RedirectIfAuthenticated{}).Group(func(route *routing.Router) {
		route.Get("/auth/{provider}/redirect", sociallogin.Redirect)
		route.Get("/auth/{provider}/callback", sociallogin.Callback)
	})
}
```


独自の `sociallogin` パッケージのリダイレクトハンドラーは、プロバイダを `social.Redirect` に渡し、そのログインページへユーザーを送ります。

```go
// handlers/sociallogin/sociallogin.go
package sociallogin

import (
	"go.laravel.com/auth/social"
	"go.laravel.com/web"
)

func Redirect(r *web.Request) *web.Response {
	return social.Redirect(r, social.Provider(r.PathValue("provider")))
}
```


`social.Redirect` は `google`、`github`、`microsoft`、および [providers you add](#adding-providers) の名前を受け取ります。URLで他の名前を指定すると `404` になります。クライアントIDとシークレットを設定していないプロバイダも `404` となり、ログの警告に設定すべき変数名が表示されます。


ログインページでInertiaの `<Link>` または通常の `<a>` タグを使い、リダイレクトルートへリンクします。`social.Redirect` は、ページ全体を読み込んでアプリケーションから移動するようInertiaへ通知します。

```tsx
import { Link } from "@inertiajs/react";

<Link href="/auth/google/redirect">Continue with Google</Link>
<Link href="/auth/microsoft/redirect">Continue with Microsoft</Link>
```

<a name="logging-the-user-in"></a>

### Logging the user in


ユーザーが承認すると、プロバイダはコールバックルートへ戻します。そこで `social.User` は、このユーザーのセッションで開始したログインのコールバックかを確認し、プロバイダへユーザー情報を問い合わせます。同じファイルの次のコールバックハンドラーは、初回訪問時にアカウントを作成し、ユーザーをログインさせます。

```go
package sociallogin

import (
	"cmp"
	"context"
	"database/sql"
	"errors"

	"go.laravel.com/auth"
	"go.laravel.com/auth/social"
	"go.laravel.com/date"
	"go.laravel.com/db"
	"go.laravel.com/inertia"
	"go.laravel.com/model"
	"go.laravel.com/web"

	"app/models"
)

func Callback(r *web.Request) *web.Response {
	profile, err := social.User(r, social.Provider(r.PathValue("provider")))
	if err != nil {
		return web.Fail(err)
	}

	user, err := findOrCreateUser(r, profile)
	if err != nil {
		return web.Fail(err)
	}
	if user == nil {
		inertia.Flash(r, "status", "We couldn't confirm your email address.")

		return web.Redirect("/login")
	}

	if err := auth.Login(r, user, true); err != nil {
		return web.Fail(err)
	}

	return auth.RedirectIntended("/dashboard")
}

func findOrCreateUser(ctx context.Context, profile *social.Profile) (*models.User, error) {
	linked, err := model.Query[models.User]().
		Where("provider", "=", profile.Provider).
		Where("provider_id", "=", profile.ID).
		First(ctx)
	if err == nil {
		return &linked, nil
	}
	if !errors.Is(err, sql.ErrNoRows) {
		return nil, err
	}

	email := profile.VerifiedEmail()
	if email == "" {
		return nil, nil
	}

	user, err := model.Query[models.User]().Where("email", "=", email).First(ctx)
	if errors.Is(err, sql.ErrNoRows) {
		now := date.Now(ctx)
		user = models.User{
			Name:            cmp.Or(profile.Name, email),
			Email:           email,
			EmailVerifiedAt: &now,
			Provider:        &profile.Provider,
			ProviderID:      &profile.ID,
		}

		return &user, model.Create(ctx, &user)
	}
	if err != nil {
		return nil, err
	}

	if user.EmailVerifiedAt == nil {
		values := db.Values{"password": nil, "email_verified_at": date.Now(ctx)}
		if err := model.Update(ctx, &user, values); err != nil {
			return nil, err
		}
	}
	if user.Provider == nil {
		values := db.Values{"provider": profile.Provider, "provider_id": profile.ID}
		if err := model.Update(ctx, &user, values); err != nil {
			return nil, err
		}
	}

	return &user, nil
}
```


ハンドラーはプロバイダ側のユーザーIDで再訪したユーザーを検索します。このIDは、プロバイダ側でメールアドレスを変更しても変わりません。常に `profile.Provider` と `profile.ID` で最初に検索し、メールだけで検索しないでください。


プロバイダが新規ユーザーのメールアドレスを確認済みなので、ハンドラーは確認済みと記録し、[verification email](/ja/go/docs/verification) は送られません。確認済みのアドレスが届かなければ `findOrCreateUser` はユーザーを返さず、ハンドラーはメッセージとともにログインページへ戻します。[`inertia.Flash`](/ja/go/docs/inertia#flash-data) でメッセージをフラッシュするため、ログインページで受け取れます。

<a name="linking-existing-accounts"></a>

### Linking existing accounts


パスワードで登録したユーザーが、後から **Google で続行** をクリックする場合があります。上のハンドラーはメールアドレスから既存アカウントを探し、Google アカウントと連携してログインさせます。


アプリケーションでメールを確認していないアカウントを連携する前に、ハンドラーはパスワードを削除し、アドレスを確認済みにします。そうしないと、他人のアドレスと自分で決めたパスワードで登録した人が、所有者のGoogleアカウント連携後もそのパスワードを使えます。削除すると、そのパスワードで作られたすべてのセッションとログイン保持クッキーもログアウトします。所有者がパスワードを必要とする場合は、[password reset](/ja/go/docs/passwords) で設定できます。


アカウントの連携には、`VerifiedEmail` が返すメールアドレスだけを使ってください。プロバイダがユーザーの所有を確認した場合にのみ返します。未確認のアドレスは他人のものかもしれません。たとえば任意のMicrosoft組織の管理者は、自分のアカウントに既存ユーザーのメールアドレスを割り当てられます。そのアドレスで連携すると、その管理者が既存ユーザーとしてログインできてしまいます。


連絡先など別の用途でアドレスが必要な場合は、`profile.Email` を読み取ります。プロバイダが未確認でもアドレスを保持し、確認済みかどうかは `profile.EmailVerified` が示します。

<a name="when-the-user-cancels"></a>

### When the user cancels


ユーザーがプロバイダの同意画面で拒否すると、`social.User` は `social.ErrDenied` を返します。`web.Fail` に渡すと `403` で応答します。多くのアプリケーションでは、コールバックハンドラーで先に確認してログインページへ戻します。

```go
profile, err := social.User(r, social.Provider(r.PathValue("provider")))
if errors.Is(err, social.ErrDenied) {
	return web.Redirect("/login")
}
if err != nil {
	return web.Fail(err)
}
```


他のエラーは `web.Fail` に渡します。`social.ErrInvalidState` は、古いコールバックURLを再び開いた場合など、このセッションのログインに属さないコールバックに対する `403` です。`*social.ProviderError` はプロバイダの失敗に対する `502` です。Laravelが報告するため、ログで原因を確認できます。

<a name="access-scopes-and-optional-parameters"></a>

### Access scopes and optional parameters


各プロバイダはデフォルトでプロフィールとメールアドレスを要求します。GitHubリポジトリへのアクセスなどを追加で求めるには、スコープを指定して `social.RedirectWith` を呼び出します。指定したスコープはデフォルトに追加されます。

```go
func ConnectGitHub(r *web.Request) *web.Response {
	return social.RedirectWith(r, social.GitHub, social.Options{Scopes: []string{"repo"}})
}
```


一部のプロバイダはリダイレクト時に追加のパラメータを受け取ります。たとえば `prompt=select_account` は、一つのアカウントにしかログインしていなくても、Google と Microsoft にアカウント選択画面を表示させます。

```go
return social.RedirectWith(r, social.Google, social.Options{
	Params: url.Values{"prompt": {"select_account"}},
})
```


`Params` に `state`、`scope`、`redirect_uri` を入れないでください。ソーシャルログインが設定するため、指定すると `RedirectWith` がパニックを起こします。スコープの要求には `Scopes` を使ってください。

<a name="retrieving-user-details"></a>

## Retrieving user details


`social.User` は `*social.Profile` を返します。フィールドは次のとおりです。

| フィールド | 型 | 保持する内容 |
| --- | --- | --- |
| `Provider` | `social.Provider` | ログインに使ったプロバイダ |
| `ID` | `string` | プロバイダ側のユーザーID。変更されません |
| `Name` | `string` | ユーザーの氏名 |
| `Nickname` | `string` | GitHubのユーザー名など。GoogleとMicrosoftにはありません |
| `Email` | `string` | プロバイダの確認状況にかかわらないメールアドレス |
| `EmailVerified` | `bool` | プロバイダが `Email` の所有を確認したかどうか |
| `Avatar` | `string` | ユーザー画像のURL。Microsoftは送信しません |
| `Token` | `social.Token` | ユーザーに代わってプロバイダAPIを呼び出すアクセストークン |
| `Raw` | `map[string]any` | プロバイダが提供したユーザー情報全体 |


プロバイダが送らなかったフィールドは空です。`Token` フィールドの `social.Token` は、`Access` にアクセストークン本体を保持します。プロバイダが送信すれば `Refresh` と `ExpiresAt` も設定し、`Scopes` はユーザーが許可したスコープの一覧です。`social.Token` の出力ではアクセストークンを隠しますが、JSONへのエンコードでは隠しません。後でAPIを呼び出す場合は、`social.Token` を [encrypted column](/ja/go/docs/encryption#encrypted-lists-and-structs) に保存してください。マイグレーションには `table.Text("github_token").Nullable()` のような `text` カラムが必要です。

```go
// models/user.go
package models

import (
	"go.laravel.com/auth/social"
	"go.laravel.com/crypt"
)

type User struct {
	ID int64 `json:"id"`
	// ...
	GitHubToken *crypt.Encrypted[social.Token] `json:"-" db:"github_token"`
}
```


フィールド名をスネークケースにすると `git_hub_token` になるため、`db` タグでカラム名を指定します。コールバックで `profile.Token` を保存し、[HTTP client](/ja/go/docs/http-client) でプロバイダAPIを呼び出す際にトークンの `Access` を読み取ります。

```go
// Store the encrypted token in your callback...
err := model.Update(r, user, db.Values{"github_token": profile.Token})

// Later, read the decrypted token to call the provider's API...
if user.GitHubToken != nil {
	repos, err := httpclient.Token(user.GitHubToken.Value.Access).
		Get(r, "https://api.github.com/user/repos")
}
```


プロバイダが送るその他の情報は、コールバックで `Raw` を読み取ります。GoogleとMicrosoftでは、`Raw` にユーザーのIDトークンのクレームが入ります。GitHubでは、会社情報を含む `/user` APIの応答が入ります。

```go
company, _ := profile.Raw["company"].(string)
```

<a name="restricting-logins-to-your-organization"></a>

### Restricting logins to your organization


自分の組織の Microsoft アカウントだけを許可するには、[`MICROSOFT_TENANT`](#microsoft) をテナント ID に設定します。Microsoft はそれ以外のユーザーを拒否します。


Googleでは、コールバックハンドラーで `social.User` がプロフィールを返した直後に確認が必要です。Google Workspaceアカウントは `hd` クレームにドメインを持ちますが、個人アカウントにはありません。

```go
if profile.Provider == social.Google && profile.Raw["hd"] != "example.com" {
	return web.Abort(http.StatusForbidden)
}
```


[`Params`](#access-scopes-and-optional-parameters) に `"hd": {"example.com"}` も渡すと、Googleのアカウント選択に組織のアカウントだけを提示できます。誰でもURLからパラメータを削除できるため、確認処理は維持してください。

<a name="adding-providers"></a>

## Adding providers


Google、GitHub、Microsoft以外にも、GitLab、Okta、KeycloakなどのOAuth 2.0プロバイダを任意の名前で登録できます。登録すると `social.Redirect`、`social.User`、`FakeSocial` がその名前を受け取り、組み込みと同じstateとPKCEの検証を行います。ルート、コールバックハンドラー、テストは変更不要です。プロバイダの開発者設定で、`/auth/gitlab/callback` などの `/auth/{provider}/callback` をコールバックURLに登録してください。


プロバイダを追加するには、`bootstrap/app.go` のオプションの `Register` 関数で、認可URL、トークンURL、ユーザー情報URLを指定した `social.OAuth2` を登録します。`app.Env()` から設定を読むと、テストで `.env.testing` と `laraveltest.Env` が反映されます。次の例はGitLabを登録し、`GITLAB_URL` でセルフホストのGitLabインスタンスを指定できます。

```go
// bootstrap/app.go
func Options() laravel.Options {
	return laravel.Options{
		Register: func(app *laravel.Registrar) error {
			gitlab := app.Env().String("GITLAB_URL", "https://gitlab.com")

			app.SocialProvider("gitlab", social.OAuth2{
				AuthorizeURL: gitlab + "/oauth/authorize",
				TokenURL:     gitlab + "/oauth/token",
				Scopes:       []string{"openid", "profile", "email"},
				ClientID:     app.Env().String("GITLAB_CLIENT_ID", ""),
				ClientSecret: app.Env().String("GITLAB_CLIENT_SECRET", ""),
				User:         social.UserInfo(gitlab + "/oauth/userinfo"),
			})

			return nil
		},
		// ...
	}
}
```

```ini
GITLAB_URL=https://gitlab.example.com
GITLAB_CLIENT_ID=
GITLAB_CLIENT_SECRET=
```


`social.UserInfo` は、GitLab、Okta、Keycloak、Auth0などが対応する標準OpenID Connectのユーザー情報エンドポイントを読み取ります。`sub` を `ID`、`preferred_username` を `Nickname`、`picture` を `Avatar` に、`name`、`email`、`email_verified` を `social.Profile` の対応するフィールドにマッピングします。GitLabの `groups` など、返されるすべてのフィールドは `Raw` でも利用できます。標準OpenID Connectクレームが返るよう、`Scopes` に `"openid"` を含めてください。


プロバイダの `ClientID` が空の場合、ルートは `404` を返します。1回のログインで追加スコープを要求するには、[`social.RedirectWith`](#access-scopes-and-optional-parameters) に渡します。


[package](/ja/go/docs/packages) として配布する場合は、パッケージの `Register` メソッド内で `app.SocialProvider("gitlab", provider)` により登録します。アプリケーションの `Register` 関数で登録したプロバイダは、パッケージとLaravel組み込みの `google`、`github`、`microsoft` の両方より優先されます。

> [!WARNING]
> `VerifiedEmail` はプロバイダの `email_verified` フィールドを信頼します。顧客のOkta組織など第三者が管理するプロバイダでは、その管理者が確認済みとするアドレスを決めます。管理者を信頼できるプロバイダでのみ、メールアドレスによる [link existing accounts](#linking-existing-accounts) を行ってください。

<a name="reading-profiles-from-the-providers-api"></a>

### Reading profiles from the provider's API


一部のOAuth 2.0プロバイダは標準OpenID Connectフィールドを返しません。たとえばDiscordはユーザー名を `username`、メール確認状態を `verified` で返します。この場合は、アクセストークンでプロフィールを取得する `User` 関数を指定してください。

```go
// bootstrap/app.go
Register: func(app *laravel.Registrar) error {
	app.SocialProvider("discord", social.OAuth2{
		AuthorizeURL: "https://discord.com/oauth2/authorize",
		TokenURL:     "https://discord.com/api/oauth2/token",
		Scopes:       []string{"identify", "email"},
		ClientID:     app.Env().String("DISCORD_CLIENT_ID", ""),
		ClientSecret: app.Env().String("DISCORD_CLIENT_SECRET", ""),
		User:         sociallogin.DiscordUser,
	})

	return nil
},
```


`User` 関数は [HTTP client](/ja/go/docs/http-client) でDiscordのAPIを呼び出し、応答を `social.Profile` にマッピングします。

```go
// handlers/sociallogin/discord.go
package sociallogin

import (
	"context"

	"go.laravel.com/auth/social"
	"go.laravel.com/httpclient"
)

func DiscordUser(ctx context.Context, token social.Token) (*social.Profile, error) {
	res, err := httpclient.Token(token.Access).
		EnsureSuccessful().
		Get(ctx, "https://discord.com/api/users/@me")
	if err != nil {
		return nil, err
	}

	type discordUser struct {
		ID       string `json:"id"`
		Username string `json:"username"`
		Name     string `json:"global_name"`
		Email    string `json:"email"`
		Verified bool   `json:"verified"`
	}
	user, err := res.JSON[discordUser]()
	if err != nil {
		return nil, err
	}

	return &social.Profile{
		ID:            user.ID,
		Name:          user.Name,
		Nickname:      user.Username,
		Email:         user.Email,
		EmailVerified: user.Verified,
	}, nil
}
```


Laravelは返されたプロフィールの `Provider` と `Token` を自動で設定します。`User` 関数がエラーまたは空の `ID` を返すと、ログインは `*social.ProviderError` で失敗し、`502` 応答になります。[linking existing accounts](#linking-existing-accounts) が依存するため、プロバイダがメールアドレスの所有を明示的に確認した場合にのみ `EmailVerified` を設定してください。

<a name="testing"></a>

## Testing


テストで実際にGoogleへログインすべきではありません。テストクライアントの `FakeSocial` は、プロバイダへの接続を省略するクライアントを返します。そこで `social.Redirect` は偽のURLへ送り、`social.User` はプロバイダへの問い合わせやセッション確認を行わず、指定したプロフィールを返します。

```go
package feature_test

import (
	"testing"

	"go.laravel.com/auth/social"
	"go.laravel.com/db"

	"app/tests"
)

func TestPeopleCanSignUpWithGoogle(t *testing.T) {
	client := tests.New(t)
	google := client.FakeSocial(social.Google, &social.Profile{
		ID:            "google-123",
		Name:          "Taylor Otwell",
		Email:         "taylor@laravel.com",
		EmailVerified: true,
	})

	google.Get("/auth/google/redirect").AssertRedirect("https://social.fake/google/authorize")
	google.Get("/auth/google/callback").AssertRedirect("/dashboard")

	client.Get("/dashboard").AssertOK()
	client.AssertDatabaseHas("users", db.Values{
		"email":       "taylor@laravel.com",
		"provider_id": "google-123",
	})
}
```


偽のクライアントは `client` とクッキーを共有するため、ログインしたユーザーは `client` のリクエストでもログイン状態を維持します。


偽のプロフィールの `Raw` は `nil` のため、[`hd` check](#restricting-logins-to-your-organization) などで読み取るとクレームが見つからず、ユーザーを拒否します。プロバイダが送るクレームを、偽のプロフィールの `Raw` に指定してください。

```go
google := client.FakeSocial(social.Google, &social.Profile{
	ID:            "google-123",
	Email:         "taylor@example.com",
	EmailVerified: true,
	Raw:           map[string]any{"hd": "example.com"},
})
```


未確認のメールアドレスを持つユーザーをテストするには、`EmailVerified` をfalseのままにします。キャンセルするユーザーには `FakeSocialDenied` を使います。次のテストは、ログインページへ戻す [When the user cancels](#when-the-user-cancels) のコールバックを想定しています。

```go
client.FakeSocialDenied(social.Microsoft).Get("/auth/microsoft/callback").AssertRedirect("/login")
```