ModernWeb
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
7
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# API 驗證授權,你所該知道的那些事 / John Liu @ TW(劉奕為) {%hackmd @ModernWeb/HkqZxb98v %} ### [簡報下載](https://s.itho.me/modernweb/2020/Slides/d202.pdf) > 共筆從這開始 ~~技術長~~ 打雜 每週二晚上[桌遊店](https://www.google.com.tw/maps/place/DeRoot%E4%BC%91%E9%96%92%E7%A9%BA%E9%96%93/@25.0406952,121.5303955,17z/data=!3m1!4b1!4m5!3m4!1s0x3442a97c6ba7c8a5:0xc2885c6f0e4f019e!8m2!3d25.0406952!4d121.5325842?shorturl=1)固定會討論web技術沒有的話就打桌遊 歡迎 8:00 後過來~ by JohnLiu ## 關於驗證 > 介紹驗證常見形式與特色 ### 驗證vs授權 * 驗證 * Authentication * 你是誰 * HTTP 401 * 授權 * Authorization * 你可以做甚麼 * HTTP 403 ### 驗證四要素 * Ownership-based authentication (你有什麼) * 實體物品,如實體金鑰(USB),信用卡・AuthenticatorApp * Characteristic-based authentication(你是什麼) * 多為生物識別,如touchID指紋辨識虹膜・語音等等。 * Knowledge-based authentication (你知道什麼) * 最常見,只有特定用戶知道的資訊,如密碼,PINcode * Location-based authentication(你在哪裡) * 與特定主機的連接或利用GPS信號來識別位置 * 不同地方登入,陌生地點登入之類的檢查。 ### Password-based authentication * 最常見的驗證機制·透過一組**帳號密碼**做使用者驗證 * 常使用Salt機制,模糊化密碼 * 此密碼不能被反推 * SHA-256最常用 * [PBKDF2](https://en.wikipedia.org/wiki/PBKDF2)可以抵禦彩虹表攻擊 * 需注意**字典攻擊**,定期透過password資料庫試user密碼 * 常見實作**2-step authentication**,先密碼後PIN值 * 透過兩階段驗證,知道你是誰 * 常見的為Google Authenticator ### 2FA ( two-factor authentication ) * 又稱**多重要素驗證**,用戶要通過兩種以上的認證機制之後·才能得到授權 * 最常見 1.先透過密碼(你知道什麼)再透邊指紋所識登入(你是什麼) 2.先透過密碼(你知道什麼)再透過特定App登入(你擴有什 * 常用在金融相關App or 公司內部登入服務 ### OTP ( one-time password ) * 一次性密碼,又稱動態密碼或單次有效密碼 * 常見透過手機裝置或Email收取一次性密碼 * 比較高規格的安全防護需求-RSA token * 實體載具 * ![RSA token](https://i.imgur.com/FPvctCc.png) * 蘋果提出之 one-time password建議規格(獲得 Google支持) ``` 747723 1s your Exampteco authentication code. @example,com #747723 ``` * PIN 的全名就叫 Personal identification number ## 關於授權 > 介紹授權常見的JWT. ### JWT ( Json Web Token) * TOKEN - 令牌、通行證 * 驗證授權常用機制,利用有規則字串辨識用戶 * 透過token知道這個人是誰 * 更符合設計 RESTfulAPI時「Stateless無狀態」原則 * 常用在 SSO(Single SignOn)使用情境、無關安全議題操作權限授與、App與IOT裝置串接API * SSO - 多個服務在同一個網站登入(Ex. Gmail、Drive) * 相較session和cookie・安全性提高 * 不須對資料庫做操作 (使用者資料可以存在前端) ![](https://i.imgur.com/VPkyn3G.png) * token在client端會存在localstorage ### JWT structure ![](https://i.imgur.com/PanlCNP.png) > payload就是資料主體啦 ### JWT payload - registrered claims > 建議要有的欄位 > 但是不是填了就會有效,要自己去實作 ![](https://i.imgur.com/iePsmwp.jpg) 3 ## 程式碼範例與總結 > Ruby與 Python 範例 Code ![](https://i.imgur.com/0lV4HbR.png) ### JWT 全貌 > 中間用`.`區隔 ![](https://i.imgur.com/ClcojbE.png) * 有工具可以直接解碼 ![](https://i.imgur.com/yfNHVE4.png) ### 關於Base64 > 不是拿來加密,他有一定的規則,就是只能拿來編碼 ### JWT的資安問題 1. Secret Key的對稱問題 * 解決方式: * 使用非對稱加密方式(RSA) * 使用組合式,或分散式金鑰 2. 非法資料問題 * 解決方式: * 使用aud, exe等JWT參數做資料的正確性核對 3. 密鑰洩漏&不指定演算法問題 4. 現實事件: * [Apple 2020/6 JWT漏洞攻撃者可以通過連結・訪問受害者帳戶](https://bhavukjain.com/blog/2020/05/30/zeroday-signin-with-apple/) 推薦閱讀:JWT做api認證安全嗎?.|by Chestermo| Medium ### 常見API加密範例-加密後簽章 * 需求描述: 以HMAC簽章驗證使用者的身份使用者在請求API服務時將APP Key與當下時間(格式使用GMT時間)做HMAC-SHA1加密運算後轉成Base64 格式,帶入signature屬性欄位,Server將驗證使用者請求時的header欄位 ![](https://i.imgur.com/DcnfuAQ.png) ### 常見 API 加密範例 - AES + IV * 需求描述: 將交易資料透過專屬加密 HashKey 與專屬加密 HashIV,產生 AES 256 加密交易資料。 ![](https://i.imgur.com/gB4qiwt.png) ## 總結 * 驗證 * 四要素:有什麼,是什麼,知道什麼和在哪裡 * 三常見方式: password, 2FA, one-time * 授權(JWT) * 優勢在於輕量、符合RESTful API原則 * 需注意資安問題 * API驗證加密常見模式: hash加密驗證、AES+IV加密 ###### tags: `MW20` `框架與設計` `API授權驗證`

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully