code4mk/kauth

kauth 是 laravel 的 JWT API 认证 ( jwt-auth )

3.0.1 2019-12-04 21:00 UTC

This package is auto-updated.

Last update: 2024-09-05 07:33:28 UTC


README

kauth

kauth

kauth 是 laravel 的 JWT API 认证 ( jwt-auth )

安装

您可以通过以下命令安装 kauth 包

composer require code4mk/kauth

配置

1) 供应商发布。

php artisan vendor:publish --provider="Kauth\KauthServiceProvider" --tag=config
php artisan vendor:publish --provider="Kauth\KauthServiceProvider" --tag=migations

2) 配置设置

  • config\kauth.php

  • 设置 token_header_name,您可以使用 guzzle 或 axios 头部使用它

  • 默认 token_header_name 名称是 tokon

使用方法

Kauth::attempt() 函数

  • guard('name')
// guard name will be user table name
Kauth::guard("users")
  • socialite()->attempt()
// laravel socialite system
// credential will be only email
Kauth::guard("users")->socialite()
        ->attempt(["email"=>"ex@gmail.com"]);
  • 常规尝试()
// your all desired credentials
// password credentail need
Kauth::guard("users")
  ->attempt(["email"=>"ex@email.com","password"=>1234])

~ attempt() 返回一个 JWT 令牌,您可以通过请求头部传递它(例如:axios 头部)

特殊尝试

  • 用户凭证将作为 (id|email|username) 可选。 (例如:facebook 用户名)
  • usernames 描述您想要匹配用户名的哪些列
attempt(["usernames"=>["id","email","name"],"username"=>"request query for username","password=>123456"]);

Kauth::check()

Kauth::check();

Kauth::id()

Kauth::id();

Kauth::refreshToken()

Kauth::refreshToken()

Kauth::logout()

Kauth::logout();

Kauth::logoutOtherDevices()

Kauth::logoutOtherDevices();