LoginSignup
1
1

More than 3 years have passed since last update.

Microsoft Graphの認証時にエラーが返された「400 Bad Request」

Last updated at Posted at 2021-02-04

結論

サポートされているアカウントの種類を個人用Microsoftアカウントのみから任意の組織ディレクトリ内のアカウントと個人のMicrosoftアカウントに変更したら認証が通りました。

エラー内容

こちらの記事をLaravelでMicrosoftアカウントを使用したSSOを実装しました。

下記のコードでリクエストを送り、

app/Http/Controllers/LoginController.php
class LoginController extends Controller
{
    public function redirectToMicrosoft()
    {
        return Socialite::driver('graph')->redirect(); 
    }
}

400 Bad Requestエラーが返ってきました。デバックして詳しくエラーを見てみます。

app/Http/Controllers/LoginController.php
class LoginController extends Controller
{
    public function redirectToMicrosoft()
    {
        return Socialite::driver('graph')->redirect(); 
    }

    public function handleMicrosoftCallback(Request $request)
    {
        dd($request);
        $user = Socialite::driver('graph')->user();
    }
}

詳しいエラー↓

"error" => "invalid_request"
"error_description" => "The request is not valid for the application's 'userAudience' configuration. In order to use /common/ endpoint, the application must not be configured with 'Consumer' as the user audience. The userAudience should be configured with 'All' to use /common/ endpoint."

翻訳してみるとcommonエンドポイントを使用するには、userAudienceを「All」で構成する必要がありますとのこと。

解消方法

Azure Active Directory 管理センターを開き、アプリを再登録しました。その際にサポートされているアカウントの種類を個人用Microsoftアカウントのみから任意の組織ディレクトリ内のアカウントと個人のMicrosoftアカウントに変更しました。

スクリーンショット 2021-02-04 14.46.42.png

サポートされているアカウントの種類を変更したことで認証が通りました。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1