An open API service indexing awesome lists of open source software.

https://github.com/ynaka6/laravel7-sanctum-token-multiauth

Laravel SanctumのToken認証を利用してMulti Authを実現するサンプル
https://github.com/ynaka6/laravel7-sanctum-token-multiauth

laravel-multiauth laravel-sanctum laravel-sanctum-token laravel7

Last synced: 16 days ago
JSON representation

Laravel SanctumのToken認証を利用してMulti Authを実現するサンプル

Awesome Lists containing this project

README

        

## 📝 About

本リポジトリは、[Laravel Sanctum](https://laravel.com/docs/7.x/sanctum)のサンプル実装です。
APIトークンを利用した認証を考慮しつつ、Multi Authを実装しています。

※ セッション認証は別途調査する予定

## 📝 認証について

`App/User`、`App/Admin`の複数Modelで、Sanctumを利用し認証します。
データについては事前にFactoryを利用し登録しています。

- ログイン処理
- ログインユーザーの取得

を中心に実装しています。

## 📝 APIリクエスト

| URL |説明 |
|---|---|
|`/api/login` |UserログインAPI |
|`/api/me` |ログインユーザー取得API |
|`/admin/api/login` |AdminログインAPI |
|`/admin/api/me` |ログイン管理ユーザー取得API |

### UserログインAPI

![/api/login - UserログインAPI](https://github.com/ynaka6/laravel7-sanctum-token/blob/master/screenshots/api_login.png)

```
curl --request POST \
--url http://127.0.0.1:8000/api/login \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"email": "[email protected]",
"password": "password"
}'
```

### ログインユーザー取得API

![/api/me - ログインユーザー取得API](https://github.com/ynaka6/laravel7-sanctum-token/blob/master/screenshots/api_me.png)

```
curl --request GET \
--url http://localhost:8000/api/me \
--header 'accept: application/json' \
--header 'authorization: Bearer 6|oW3GIXpw48kcfAc1FcqA4gm4zOBFfVgNVGdMCqIImFMzoaEmTqSY4fsOFNxXymPnXPFXU5mfMYg7pMI7'
```

### AdminログインAPI

![/admin/api/login - AdminログインAPI](https://github.com/ynaka6/laravel7-sanctum-token/blob/master/screenshots/admin_api_login.png)

```
curl --request POST \
--url http://127.0.0.1:8000/admin/api/login \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
"email": "[email protected]",
"password": "password"
}'
```

### ログイン管理ユーザー取得API

![/admin/api/me - ログイン管理ユーザー取得API](https://github.com/ynaka6/laravel7-sanctum-token/blob/master/screenshots/admin_api_me.png)

```
curl --request GET \
--url http://127.0.0.1:8000/admin/api/me \
--header 'accept: application/json' \
--header 'authorization: Bearer 4|dbtGtsoXAyE7VH1yaIpvDsI3F2UqelBl2YkOI8j17xvqCgfU5k4kk9D37OhlBpTur2uJUcttwCGSFV1U'
```

## Tools
- [Insomnia](https://insomnia.rest/) : HTTPクライアント

## License

The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).