ดู authentication tokens และ session cookies ของเว็บแอพบน Azure App Service ด้วย nodejs

  1. สร้าง Azure App Service
  2. กำหนดวิธี Deploy ของ App Service ให้เป็น Local Git
  3. clone ตัวอย่าง nodejs
  4. Authentication และดู Token

1.สร้าง Azure App Service

  • Name: nodeappserver
  • Runtime stack: Node LTS

2.กำหนดวิธี 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

เลือก 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