- สร้าง Azure App Service
- กำหนดวิธี Deploy ของ App Service ให้เป็น Local Git
- clone ตัวอย่าง nodejs
- Authentication และดู Token
1.สร้าง Azure App Service
- Name:
nodeappserver
- Runtime stack:
Node LTS
2.กำหนดวิธี Deploy ของ App Service ให้เป็น Local Git
- ดู Deploy code ไป App Service ด้วย Local Git repository ข้อ 1.กำหนดวิธี Deploy ของ App Service ให้เป็น Local Git
3.clone ตัวอย่าง nodejs
clone ตัวอย่าง nodejs ลงมา
$ git clone https://github.com/Azure-Samples/nodejs-docs-hello-world.git $ cd nodejs-docs-hello-world/
add production ด้วย git url ของ App Service เรา
$ git remote add production https://nodeappserver.scm.azurewebsites.net:443/nodeappserver.git
อัพโค๊ดขึ้น App Service ที่ https://nodeappserver.azurewebsites.net/
$ git push production
เรียก App Service จะขึ้น Hello World
4.Authentication และดู Token
- Authenticate browser-based apps with Azure App Services
- ดู ให้เว็บแอพ authen ด้วย Microsoft Authentication provider
- 2.ลงทะเบียน Web App ที่ Application Registration Portal
- 3.คอนฟิก App Service ให้บังคับ Authentication
เลือก Action to take when request is not authenticated เป็น Allow Anonymous requests (no action)
แก้ไขโค้ดที่ไฟล์ index.js ให้แสดง link สำหรับ login และแสดง token
(ในกรณีที่ login)
const http = require('http'); const server = http.createServer((request, response) => { response.writeHead(200, {"Content-Type": "text/html"}); response.write("Welcome to my website!<br/>"); response.write("<a href='/.auth/login/microsoftaccount'>Log in with Microsoft Account</a>"); response.write("<br/>"); response.write("<a href='/.auth/me'>View token</a>"); response.end(); }); const port = process.env.PORT || 1337; server.listen(port); console.log("Server running at http://localhost:%d", port);
push โค๊ดขึ้น App Service อีกครั้ง
$ git add . $ git commit -m "Edit App Code to Return the Token" $ git push production
คลิก View token จะ error ให้ login ก่อน แล้วค่อยกลับมาคลิก View token แล้วจะเห็น token ต่างๆ
- access_token
- expires_on
- provider_name
- user_claims
- user_id