Wednesday, September 19, 2018

OAuth





Scopes
OAuth scopes are used to limit an application’s access to user data

During authorization, the API provider will display all the requested scopes to the user. This way, users will know what permissions they are granting to an application.

A minimal scope
Isolate scopes for protecting sensitive information
Differentiate scopes for different kinds of resources
GitHub has different scopes for accessing different resources, like the repositories, managing organization, public keys, notifications, and gists. This means that an application requesting access to only a user’s repositories will not be granted access to that user’s gists.


X-OAuth-Scopes lists the scopes for  which a token has been authorized.

X-Accepted-OAuth-Scopes lists the scopes that the action requires.


Token Expiry and Refresh Tokens
A refresh token is a special type of token used to obtain a new access token when the current access token expires. Applications need to provide the client ID, client secret, and refresh token to generate a new access token. Refresh tokens are a standard way of renewing expired access tokens.

Even if your access tokens do not expire, it can be a good idea to share refresh tokens.

Short-lived authorization codes
One-time-use refresh tokens
it is a good idea to allow applications to use refresh tokens for a small window of time so that they can retry if there was a network failure or another issue. The Fitbit API allows a refresh token to be reused for up to two minutes.

Ability to reset the client secret
OAuth scopes for sensitive information
HTTPS endpoints
Verify redirect URL

Disallow rendering the authorization screen in iframes
Use the X-Frame-Options header to deny rendering an authorization page in an iframe.
Keep users informed
Prohibit misleading application names
Do not allow apps to use names that might mislead users into thinking that an outside application was created by your company. One way to enforce this is by denying apps permission to use your company name in OAuth application names.

WebHooks Security
Verification Tokens
Request Signing and WebHook Signatures
Signatures are among the most common ways API providers choose to secure WebHooks. WebHook payloads are typically signed by computing a hash-based message authentication code (HMAC) of a shared secret plus the request body, and the signature is sent as part of a request header. Applications then verify the authenticity of the request by computing the same HMAC and comparing it to the value set in the header

PREVENTING REPLAY ATTACKS
A replay attack is a form of attack in which an attacker retransmits a WebHook with a valid signature. To mitigate such attacks, API providers like Stripe include a request timestamp in the message payload. If the timestamp is too old, applications can reject the request.

Thin Payloads and API Retrieval
A more secure option is to send limited information in the payload indicating to the application that something has changed. To retrieve the full event, the application would need to make a subsequent request to the web API. The key benefit of this approach is that even if applications do not verify the WebHook, they will receive the full event only after making regular authenticated requests to a web API. 

Gmail’s API allows applications to subscribe to watch for changes in an inbox using WebHooks. When something changes, Gmail sends a WebHook request, including the email address and an ID for the change. Applications can call Gmail’s history.list web API to retrieve the full change details.



Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts