Securing ASP.NET Core 2.0 Applications with JWTs

Securing ASP.NET Core 2.0 Applications with JWTs

โหลดตัวอย่างมาจาก Git Using JWTs in .NET Core 2

เปิดขึ้นมาแล้วลองรัน
browser จะชี้ไปที่ http://localhost:63939/api/books ซึ่งจะ Error ดังนี้
This page isn’t working
If the problem continues, contact the site owner.
HTTP ERROR 401

แล้วถ้าเรียกไปที่ http://localhost:63939/api/token ก็จะ Error แบบนี้
This localhost page can’t be found
No webpage was found for the web address: http://localhost:63939/api/token
Search Google for localhost 63939 api token
HTTP ERROR 404

เป็นเพราะไม่ได้ส่งพารามิเตอร์ที่จำเป็นไปให้

ทีนี้ลองใช้ Postman เรียกไปที่ http://localhost:63939/api/token
พร้อมส่งค่าไปดังนี้

[code]
{
"username": "mario",
"password": "secret"
}
[/code]

จะได้ค่าคืนมาเป็นแบบข้างล่างนี้ก็เป็นอันใช้ได้

[code]
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJNYXJpbyBSb3NzaSIsImVtYWlsIjoibWFyaW8ucm9zc2lAZG9tYWluLmNvbSIsImJpcnRoZGF0ZSI6IjI1MjYtMDktMjMiLCJqdGkiOiJhYzdlYWRhZS02YzI4LTRlMDctOWM2OC1mMjAxMjNjYWY1OTUiLCJleHAiOjE1MzU1MzI2NTUsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjM5MzkvIiwiYXVkIjoiaHR0cDovL2xvY2FsaG9zdDo2MzkzOS8ifQ.dCmNVlejU4kjQI1NNZRbBPXZ19AKQmWwekHT8aSCAsY"
}
[/code]

 

Continue reading

WordPress plugin แสดง TOC แบบรองรับหลายหน้า

การแสดง TOC แบบรองรับ multipage ด้วย plugin ชื่อ Extended Table of Contents (with nextpage support) 

 

การติดตั้งปลั๊กอิน Extended Table of Contents

เข้า WordPress admin
แล้วเลือกเมนู Plugins > Add Plugins ค้นหาด้วยคำว่า toc

จะปรากฏหน้าจอ

ทำการติดตั้งโดยกด Install Now เสร็จแล้วกด Activate

การใช้ ionic เรียก WebApi เป็น Object

1. สร้างโปรเจ็กส์ ASP.NET Core

สร้างโปรเจ็กส์แบบ ASP.NET Core WebAPI in Azure

Startup.cs

ValuesController.cs

2. สร้างโปรเจ็กส์ ionic

สร้างโปรเจ็กส์ ionic เรียกใช้ HTTP แบบ Native (GET)

home.html

home.ts

3. ผลการรัน

ลองใช้ Postman ทำการ POST

[code]
{
"ID": 101,
"FirstName": "Phaisarn",
"LastName": "Sutheebanjard"
}
[/code]

ได้ผลลัพธ์กลับมาเป็น

[code]
101 : Phaisarn Sutheebanjard
[/code]

เรียกผ่าน browser แบบ Get

ไปที่ http://jackwebapi25610824112107.azurewebsites.net/api/values/1

ได้ผลลัพธ์กลับมาเป็น

[code]
{"id":50,"firstName":"Phaisarn","lastName":"Sutheebanjard"}
[/code]

ใช้ ionic เรียกแบบ Get

[code]
http://jackwebapi25610824112107.azurewebsites.net/api/values/1
this.stStatus 200
this.stValue {"id":50,"firstName":"Phaisarn","lastName":"Sutheebanjard"}
person[‘id’] 50
person[‘firstName’] Phaisarn
person[‘lastName’] Sutheebanjard
[/code]

ใช้ ionic เรียกแบบ Post

[code]
this.stStatus 200
this.stValue 101 : Phaisarn Sutheebanjard
[/code]

Docker: ทดลองใช้งาน busybox

1. ดึง image ชื่อ busybox มาติดตั้ง

[code]
PS C:\Users\phaisarn.sut\docker> docker pull busybox
Using default tag: latest
latest: Pulling from library/busybox
8c5a7da1afbc: Pull complete
Digest: sha256:cb63aa0641a885f54de20f61d152187419e8f6b159ed11a251a09d115fdff9bd
Status: Downloaded newer image for busybox:latest
[/code]

หรือกำหนด tag ด้วย เลขเวอร์ชันได้ docker run busybox:1.29.2

Continue reading

ionic: ปัญหา Date

Javascript date is invalid on iOS

Your date string is not in a format specified to work with new Date. The only format in the spec is a simplified version of ISO-8601, but that was only added in ES5 and so support may be touch and go. Your string isn’t in that format, but it’s really close.

Note that there was an error in the ES5 specification which was corrected in ES2015 (ES6):

พยายามหลีกเลี่ยงการกำหนดค่าให้กับตัวแปร Date โดยตรง
เช่น กำหนดให้เป็นวันที่ปัจจุบันก่อน แล้วค่อยกำหนดวัน กำหนเดือน ดังตัวอย่างนี้

[code]
this.date = new Date();
this.date.setDate(2); // 2
this.date.setMonth(5); // june
[/code]

*โดย Jan น่าจะเริ่ม่ที่ 0

อันนี้น่าจะแก้ปัญหาได้นะ น่าจะ work!!

[code]
var firstDayThisMonth = new Date(this.date.getFullYear(), this.date.getMonth(), 1).getDay();
[/code]

เป็นการกำหนดให้เป็นวันที่ 1 ของเดือนปี ที่กำหนด

แต่ถ้าต้องการแค่เปรียบเทียบว่าวันที่ตรงกันมั๊ย กำหนดให้เป็น string แทน เช่น

[code]
let thisDate = this.date.getFullYear() + "-" + month + "-" + date;
[/code]