[ laravel 5.4 ææ¡£ ] å®å ¨ — api认è¯ï¼passportï¼_php_web-itnose
é¦é¡µ
asp
php
javascript
iis
apache
html/css
coldfusion
ajax
vbscript
cgi
xml/xsl
è·¨æµè§å¨å¼å
ruby/rails
ç¨åºå
html5
jquery
seo
jboss
json
angularjs
markdown
nginx
thinkphp
yii
pageadmin
extjs
wampserver
kendo ui
coffeescript
gulp
ecmascript
bootstrap
itnoseé¦é¡µ > web > php >
[ laravel 5.4 ææ¡£ ] å®å ¨ — api认è¯ï¼passportï¼
2017-02-20 12:55
1ãç®ä»
laravel éè¿ä¼ ç»çç»å½è¡¨åå·²ç»è®©ç¨æ·è®¤è¯åå¾å¾ç®åï¼ä½æ¯api æä¹åï¼api é常使ç¨tokenè¿è¡è®¤è¯å¹¶ä¸å¨è¯·æ±ä¹é´ä¸ç»´æ¤ session ç¶æãlaravel ä½¿ç¨ laravelpassport 让api 认è¯åå¾è½»èæ举ï¼passport åºäº alex bilbie ç»´æ¤ç league oauth2 server
ï¼å¯ä»¥å¨æ°åéå
为laravelåºç¨æä¾å®æ´çoauth2 æå¡å¨å®ç°ã
注ï¼æ¬ææ¡£åè®¾ä½ å·²ç»å¾çæ oauth2ï¼å¦æä½ å¯¹ oauth2 ä¸æ æç¥ï¼é£ä¹å¨å¼å§å¦ä¹ æ¬ææ¡£ä¹åï¼å
è¦å»çæoauth2çä¸äºæ¯è¯åç¹æ§ï¼åèé®ä¸å³°åå®¢ï¼ ç解oauth 2.0
ï¼ã
2ãå®è£
ä½¿ç¨ composer å 管çå¨å®è£ passportï¼
composer require laravel/passport
æ¥ä¸æ¥ï¼å¨é
ç½®æ件 config/app.php
ç providers
æ°ç»ä¸æ³¨å passport æå¡æä¾è
ï¼
laravel\passport\passportserviceprovider::class,
passport æå¡æä¾ç为æ¡æ¶æ³¨åäºèªå·±çæ°æ®åºè¿ç§»ç®å½ï¼æ以å¨æ³¨åä¹åéè¦è¿ç§»æ°æ®åºï¼passport è¿ç§»å°ä¼ä¸ºåºç¨çæç¨äºåæ¾å®¢æ·ç«¯å访é®ä»¤ççæ°æ®è¡¨ï¼
php artisan migrate
注ï¼å¦æä½ ä¸åå¤ä½¿ç¨ passport é»è®¤çè¿ç§»ï¼éè¦å¨ appserviceprovider
ç register
æ¹æ³ä¸è°ç¨ passport::ignoremigrations
æ¹æ³ãä½ å¯ä»¥ä½¿ç¨ php artisan vendor:publish –tag=passport-migrations
导åºé»è®¤è¿ç§»ã
æ¥ä¸æ¥ï¼éè¦è¿è¡ passport:install
å½ä»¤ï¼è¯¥å½ä»¤å°ä¼å建çæå®å
¨è®¿é®ä»¤çï¼tokenï¼æéçå å¯é®ï¼æ¤å¤ï¼è¯¥å½ä»¤è¿ä¼å建âpersonal accessâåâpassword grantâ客æ·ç«¯ç¨äºçæ访é®ä»¤çï¼
php artisan passport:install
è¿è¡å®è¿ä¸ªå½ä»¤åï¼æ·»å laravel\passport\hasapitokens
traitå° app\user
模åï¼è¯¥traitå°ä¼ä¸ºæ¨¡åç±»æä¾ä¸äºè¾
å©å½æ°ç¨äºæ£æ¥è®¤è¯ç¨æ·çtokenåscopeï¼
[
‘app\listeners\revokeoldtokens’,
],
‘laravel\passport\events\refreshtokencreated’ => [
‘app\listeners\pruneoldtokens’,
],
];
13ãæµè¯
passport ç actionas
æ¹æ³å¯ä»¥ç¨äºæå®å½åç认è¯ç¨æ·ä»¥åä½ç¨åï¼ä¼ éç» actionas
æ¹æ³ç第ä¸ä¸ªåæ°æ¯ç¨æ·å®ä¾ï¼ç¬¬äºä¸ªæ¯åæ¾ç»ç¨æ·ä»¤ççä½ç¨åæ°ç»ï¼
public function testservercreation()
{
passport::actingas(
factory(user::class)->create(),
[‘create-servers’]
);
$response = $this->post(‘/api/create-server’);
$response->assertstatus(200);
}
ç¸å
³æç´¢ï¼
jsp api
ejb api
spring api
delphi api
webservice å®å
¨
ç¸å ³æç«
2017-02-18 03:50 [ laravel 5.4 ææ¡£ ] å®å
¨ — ç¨æ·è®¤è¯
2017-02-21 04:09 [ laravel 5.4 ææ¡£ ] å®å
¨ — å å¯
2017-03-22 00:27 laravel5.4 api token认è¯
2017-02-21 00:20 [ laravel 5.4 ææ¡£ ] å®å
¨ — ç¨æ·ææ
2016-09-12 03:14 [ laravel 5.3 ææ¡£ ] å®å
¨ — ç¨æ·è®¤è¯
æ´å¤ç¸å ³æç« >>
ææ°æç«
2017-06-20 01:35 èé们ï¼æ没æå¯è½è®©phpæ件åæ¶åªè½ä¸ä¸ªäººè®¿é®
2017-06-20 01:35 æä¹ç¦æ¢å¾çç´æ¥éè¿url访é®
2017-06-20 01:35 æ±æ!å¯å¨wampåªè½ç¨æ¬æºè®¿é®,åå±åç½çå
¶å®è®¾å¤è®¿é®ä¸å°!æäºå¤§å天t-t
2017-06-19 15:35 nginxä¸çthinkphpé®é¢
2017-06-19 15:35 php form æ件ä¸ä¼
æ´å¤ææ°æç« >>
çé¨æç´¢
webserviceå®å
¨
jspææ¡£
hibernateææ¡£
.netææ¡£
xmlææ¡£
hibernate api chm
hibernate api å¨çº¿
hibernateä¸æapi
java web api
vb.net api
.net web api
jspå®å
¨å¸½
ejbå®å
¨æ§
asp.netå®å
¨
java webservice å®å
¨
京icpå¤14022385å·-2
©2014 itnose软件ç¼ç¨æç¨ | èç³»æ们ï¼emailï¼twobrushes@126.com qq:35155868