gpt4 book ai didi

php - Laravel Sanctum Auth 问题

转载 作者:行者123 更新时间:2023-12-05 06:15:59 30 4
gpt4 key购买 nike

我在使用子域和 laravel sanctum 时遇到问题。在子域上,我未获得授权。它在本地工作得很好。

我已将域添加到 sanctum domain/.env。我还根据关于子域的 laravel 文档设置了 cors/config,但没有成功。网站上有一个 Htpasswd,这会导致问题吗?我没有想法:(。

有没有人在使用 htpasswd 时遇到过这种情况?如果您需要一些代码,请随时询问,

编辑*

cors配置

return [

/*
|--------------------------------------------------------------------------
| Cross-Origin Resource Sharing (CORS) Configuration
|--------------------------------------------------------------------------
|
| Here you may configure your settings for cross-origin resource sharing
| or "CORS". This determines what cross-origin operations may execute
| in web browsers. You are free to adjust these settings as needed.
|
| To learn more: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
*/

'paths' => ['api/*'],

'allowed_methods' => ['*'],

'allowed_origins' => ['*'],

'allowed_origins_patterns' => [],

'allowed_headers' => ['*'],

'exposed_headers' => [],

'max_age' => 0,

'supports_credentials' => true,

];

密室配置

return [

/*
|--------------------------------------------------------------------------
| Stateful Domains
|--------------------------------------------------------------------------
|
| Requests from the following domains / hosts will receive stateful API
| authentication cookies. Typically, these should include your local
| and production domains which access your API via a frontend SPA.
|
*/

'stateful' => explode(',', env('SANCTUM_STATEFUL_DOMAINS', 'localhost,127.0.0.1')),

/*
|--------------------------------------------------------------------------
| Expiration Minutes
|--------------------------------------------------------------------------
|
| This value controls the number of minutes until an issued token will be
| considered expired. If this value is null, personal access tokens do
| not expire. This won't tweak the lifetime of first-party sessions.
|
*/

'expiration' => null,

/*
|--------------------------------------------------------------------------
| Sanctum Middleware
|--------------------------------------------------------------------------
|
| When authenticating your first-party SPA with Sanctum you may need to
| customize some of the middleware Sanctum uses while processing the
| request. You may change the middleware listed below as required.
|
*/

'middleware' => [
'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class,
'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class,
],

];

.环境

APP_NAME="Events"
APP_ENV=local
APP_KEY=base64:COUzIB3fLtC9H7VYX4UdQAx8I2V7Hq9BoeJNjPATwMM=
APP_DEBUG=true
APP_URL=http://events.hiddendomain.com

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hiddenname
DB_USERNAME=hiddenuser
DB_PASSWORD=hiddenpw

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=cookie
SESSION_LIFETIME=120
SESSION_DOMAIN='.hiddendomain.com'
SANCTUM_STATEFUL_DOMAIN="events.hiddendomain.com"

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

我将其添加到 axios

axios.defaults.withCredentials = true;

Vue调用

getEventDays() {
axios.get(`/api/event/${this.eventSlug}/${this.slugify(this.selectedAgendaType)}/get-days`)
.then((res) => {
// Set the days
this.days = res.data.data;
// set the selected day to the day id
this.selectedDay = res.data.data[0].id;
// get the sessions for the day(selectedDay) e.g api call
this.getDayWithSessions();
})
.catch((err) => console.error(err.response || err));
},

我已经删除了域名,因为我不能透露名称,但原理是一样的。

人们要求提供代码,但是密室并不多。该站点不是完整的 SPA。我只是在 Blade View 中使用一个 vue 组件。

更新

我已经删除了 htpasswd,但问题仍然存在。我可能有 30 个不同的网站,每个网站上的一切都是一样的,但没有运气让它在子域上工作

更新

我已经通过使用 valet 并设置子域在我的本地主机上复制了它。出现完全相同的问题!

提前致谢。

最佳答案

您只需要允许顶级域名,Laravel Sanctum 不需要您的子域全名作为允许的有状态域。

在您的情况下,允许 hiddendomain.com 就足够了。

SANCTUM_STATEFUL_DOMAINS=hiddendomain.com

希望对您有所帮助。

问候。

关于php - Laravel Sanctum Auth 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62269976/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com