AADSTS50011:请求中指定的回复 URL 与 Laravel Socialite 中的回复不匹配
AADSTS50011: The reply URL specified in the request does not match the reply in Laravel Socialite
我正在使用 Laravel-5.8 进行用户 Azure AD 身份验证。我安装了这个包:
"socialiteproviders/microsoft-azure": "^3.0",
作曲家要求 socialiteproviders/microsoft-azure
我也做了配置。从数据库常规登录正在完善,但我对 Laravel microsoft-azure 集成有问题。
登录控制器
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Socialite;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/dashboard';
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function redirectToProvider()
{
return Socialite::with('azure')->redirect();
}
public function handleProviderCallback()
{
$user = Socialite::with('azure')->user();
}
查看blade:
login.blade
<form class="login-form" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class=" w3l-form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label>Username:</label>
<div class="group">
<i class="fas fa-user"></i>
<input id="email" type="text" class="form-control" name="email" placeholder="Email" required autofocus>
<div>
</div>
</div>
</div>
<div>
@if ($errors->has('email'))
<span class="help-block" style="color: red">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class=" w3l-form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label>Password:</label>
<div class="group">
<i class="fas fa-unlock"></i>
<input id="password" type="password" class="form-control" name="password" placeholder="Password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<button type="submit">Login</button>
<a href="{{ route('azure.login') }}" class="btn btn-primary"> Azure Login</a>
</form>
我正在使用 Laravel-5.8 进行用户 Azure AD 身份验证。我安装了这个包:
"socialiteproviders/microsoft-azure": "^3.0",
作曲家要求 socialiteproviders/microsoft-azure
我也做了配置。从数据库常规登录正在完善,但我对 Laravel microsoft-azure 集成有问题。
登录控制器
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Socialite;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/dashboard';
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function redirectToProvider()
{
return Socialite::with('azure')->redirect();
}
public function handleProviderCallback()
{
$user = Socialite::with('azure')->user();
}
login.blade
<form class="login-form" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class=" w3l-form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label>Username:</label>
<div class="group">
<i class="fas fa-user"></i>
<input id="email" type="text" class="form-control" name="email" placeholder="Email" required autofocus>
<div>
</div>
</div>
</div>
<div>
@if ($errors->has('email'))
<span class="help-block" style="color: red">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class=" w3l-form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label>Password:</label>
<div class="group">
<i class="fas fa-unlock"></i>
<input id="password" type="password" class="form-control" name="password" placeholder="Password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<button type="submit">Login</button>
<a href="{{ route('azure.login') }}" class="btn btn-primary"> Azure Login</a>
</form>
展开代码段
route/web.php
Route::get('login/azure', 'Auth\LoginController@redirectToProvider')->name('azure.login');
Route::get('login/azure/callback', 'Auth\LoginController@handleProviderCallback');
config/services
'azure' => [
'client_id' => env('AZURE_KEY','hsdhsdhsd'),
'client_secret' => env('AZURE_SECRET','jfhrbdjf'),
'redirect' => env('AZURE_REDIRECT_URI','https://laravelproject.laraapps.net/login/azure/callback')
],
它在生产中,所以我不再使用 .env
config/app
\SocialiteProviders\Manager\ServiceProvider::class,
当我单击 Azure 登录按钮时,屏幕截图中出现此错误:
这是我的 Azure AD 重定向 URL"
如何解决?
谢谢。
您可以在输入凭据之前在授权端点中找到真正的 redirect_uri。
类似于https://login.microsoftonline.com/{tenant}/oauth2/authorize? client_id=6731de76-14a6-49ae-97bc-6eba6914391e &response_type=code &redirect_uri=http%3A%2F%2Flocalhost%3A12345 &response_mode=query &resource=https%3A%2F%2Fservice.contoso.com%2F &state=12345
确保此 redirect_uri 与 Azure 门户中的相同。
我正在使用 Laravel-5.8 进行用户 Azure AD 身份验证。我安装了这个包:
"socialiteproviders/microsoft-azure": "^3.0",
作曲家要求 socialiteproviders/microsoft-azure
我也做了配置。从数据库常规登录正在完善,但我对 Laravel microsoft-azure 集成有问题。
登录控制器
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Socialite;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/dashboard';
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function redirectToProvider()
{
return Socialite::with('azure')->redirect();
}
public function handleProviderCallback()
{
$user = Socialite::with('azure')->user();
}
查看blade:
login.blade
<form class="login-form" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class=" w3l-form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label>Username:</label>
<div class="group">
<i class="fas fa-user"></i>
<input id="email" type="text" class="form-control" name="email" placeholder="Email" required autofocus>
<div>
</div>
</div>
</div>
<div>
@if ($errors->has('email'))
<span class="help-block" style="color: red">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class=" w3l-form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label>Password:</label>
<div class="group">
<i class="fas fa-unlock"></i>
<input id="password" type="password" class="form-control" name="password" placeholder="Password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<button type="submit">Login</button>
<a href="{{ route('azure.login') }}" class="btn btn-primary"> Azure Login</a>
</form>
我正在使用 Laravel-5.8 进行用户 Azure AD 身份验证。我安装了这个包:
"socialiteproviders/microsoft-azure": "^3.0",
作曲家要求 socialiteproviders/microsoft-azure
我也做了配置。从数据库常规登录正在完善,但我对 Laravel microsoft-azure 集成有问题。
登录控制器
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Socialite;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = '/dashboard';
public function __construct()
{
$this->middleware('guest')->except('logout');
}
public function redirectToProvider()
{
return Socialite::with('azure')->redirect();
}
public function handleProviderCallback()
{
$user = Socialite::with('azure')->user();
}
login.blade
<form class="login-form" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class=" w3l-form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label>Username:</label>
<div class="group">
<i class="fas fa-user"></i>
<input id="email" type="text" class="form-control" name="email" placeholder="Email" required autofocus>
<div>
</div>
</div>
</div>
<div>
@if ($errors->has('email'))
<span class="help-block" style="color: red">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<div class=" w3l-form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label>Password:</label>
<div class="group">
<i class="fas fa-unlock"></i>
<input id="password" type="password" class="form-control" name="password" placeholder="Password" required>
@if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
@endif
</div>
</div>
<button type="submit">Login</button>
<a href="{{ route('azure.login') }}" class="btn btn-primary"> Azure Login</a>
</form>
展开代码段
route/web.php
Route::get('login/azure', 'Auth\LoginController@redirectToProvider')->name('azure.login');
Route::get('login/azure/callback', 'Auth\LoginController@handleProviderCallback');
config/services
'azure' => [
'client_id' => env('AZURE_KEY','hsdhsdhsd'),
'client_secret' => env('AZURE_SECRET','jfhrbdjf'),
'redirect' => env('AZURE_REDIRECT_URI','https://laravelproject.laraapps.net/login/azure/callback')
],
它在生产中,所以我不再使用 .env
config/app
\SocialiteProviders\Manager\ServiceProvider::class,
当我单击 Azure 登录按钮时,屏幕截图中出现此错误:
这是我的 Azure AD 重定向 URL"
如何解决?
谢谢。
您可以在输入凭据之前在授权端点中找到真正的 redirect_uri。
类似于https://login.microsoftonline.com/{tenant}/oauth2/authorize? client_id=6731de76-14a6-49ae-97bc-6eba6914391e &response_type=code &redirect_uri=http%3A%2F%2Flocalhost%3A12345 &response_mode=query &resource=https%3A%2F%2Fservice.contoso.com%2F &state=12345
确保此 redirect_uri 与 Azure 门户中的相同。