laravel api 認證使用了 passport 的密碼驗證方式, 在做手機短信驗證碼登錄時, 由於獲取不到 明文密碼,無法獲取 token
用 laravel 個人訪問令牌獲取 token 時, 獲取到的 token 有效期為一年, 且無法獲取 refresh_token
查看源碼, 在laravel\passport\src\Bridge\UserRepository.php 的 getUserEntityByUserCredentials() 函數中會看到這段代碼:
所以采用 在數據庫里存的hash加密后的密碼來驗證, 即在 user model 中重寫密碼驗證方法: validateForPassportPasswordGrant
在controller中, 在需要登錄的地方使用 Guzzle 發送請求 即可獲取 token
獲取token數據