Kai 2-API-Basics.pdf
Kai 2-API-Basics.pdf
Kai 2-API-Basics.pdf
Fichier Détails
Cartes-fiches | 15 |
---|---|
Langue | English |
Catégorie | Informatique |
Niveau | Université |
Crée / Actualisé | 02.07.2019 / 02.07.2019 |
Lien de web |
https://card2brain.ch/box/20190702_kai_2apibasics_pdf
|
Intégrer |
<iframe src="https://card2brain.ch/box/20190702_kai_2apibasics_pdf/embed" width="780" height="150" scrolling="no" frameborder="0"></iframe>
|
Créer ou copier des fichiers d'apprentissage
Avec un upgrade tu peux créer ou copier des fichiers d'apprentissage sans limite et utiliser de nombreuses fonctions supplémentaires.
Connecte-toi pour voir toutes les cartes.
What is JSON?
JSON = JavaScript Opject Notation
- Language-independent data format for data interchange
- Subset of JavaScript
- Good documentation: http://json.org
- ECMA Standard
JavaScript Object Notation (JSON) is a lightweight, text-based, language-independent data interchange format. It was derived from the ECMAScript Programming Language Standard. JSON defines a small set of formatting rules for the portable representation of structured data.
What is the gramar of JSON
<value> ::= true | flase
<number> |
<string> |
<array> |
<object>
What are the JSON (JavaScript Object Notation) data types?
Number:
- Decimal, possibly signed
- Both integer or floating point
- May use exponential E notation
- Example: 3.22
Array:
- Orderd list of values
- Possibley empty
- Example: [123, "abc", 324.23]
String:
- A sequence of unicode characters
- Delimited by: "
- Escaped by: \
- Example: "This is a: \t string"
Object:
- Unorderd list of key/value pairs
- Possibly empty
- Keys are strings
- Example: {"key1": 123, "key2": "blah"}
What are some prperties of the JSON notation?
What is REST
REST = REpresentational State Transfer
- Servers expose resources using a URI
- Server store no state about client (no session)
- Client transfers its state with each request
REST (REpresentational State Transfer) is a sofware architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style are called RESTful Web services (RWS). they provide interoperability between computer systems on the internet.
What are the 4 HTTP Verbs?
Clients access REST resources using the four HTTP verbs:
- DELETE
- GET
- POST (create)
- PUT (update)
What are the best prctices for REST?
- Use self-explanatory nouns in your URLs
- Choose a URI for each resource you wish to expose
- GET should not change any data
- PUT and DELETE should be idempotent (multiple executions have the same result as a singe execution)
- Use links in your responses
- Use the HTTP Accept request header to chose representation (XML, JSON, ...)
- Use the Cache-Control response header ot control chaching
- GET responses are cached by default,
- POST/PUT responses are not
- Set cahce-control: private to signal that data is specific to current user
- Use the Content-Type response header to specify the representation
- Use appropriate HTTP error codes
What are the relevant HTTP Error Codes?
- 200 OK: Request was successful
- 201 Created: Request was successful and resource was created (PUT or POST)
- 400 Bad Request: Request was malformed. (PUT or POST request in the wrong format)
- 404: Not Found: Resource for that URL could not be found
- 401: Unauthorized: Authentication failed
- 403: Forbidden: Insufficent rights
- GitHub returns 404 when you try to access someone else's (existing) user account -> no information disclosure
- 405: Method Not Allowed
- 500: Internal Server Error: failed to fulfill an apparently valid request
What are the characteristics of HTTP Basic Authentication?
- Easiiest way to send username and password to a server
- Standardized by the IETF in RFC2617
- Process:
- Concatenate username and password like this: "john:password"
- Base64encode
- Put thes string after "Basic " in the Authorization header:
Authorization: Basic am9wehEJSHJL==
- Password is transmitted in cleartext needs TLS
- The browser sends this only after gettin g a response with status 401 Unauthorized with a challenge like this:
- WWW-Authenticate: Basic realm="Wallys World"
- For API access credentials are of course usually sent preemptively
What are Access Tokens?
Access Tokens:
- Most APIs that use HTTP Basic Authentication use server-generated access tokens instead of username/password
- They are often called API Keys or API Access Tokens, such as on GitHub
What are the advantages of Access Tokens vs. username/password
Benefits of access tokens vs. usrename/password
- Higher entropy: harder to guess
- Can create separate access tokens for separate applications
- Revoke-able
- Scope-able
What is SSL Client Authentication also known as?
SSL Client Authentication
Also known as:
- Mutual SSL
- SSL with Mutual Authentication
- Two-Way SSL
- SSL with Client-Certificate
- Rarely used for communication with end-users
- Very much used for internal and B2B communication
Draw the flow of a two way ssl handshake
Draw the detailed SSL handshake between server and client.
- Client to Server: "client hello"
- Server to Client: "server hello" + CipherSuite (what versions and protocols the server suportes)
+ Server certificate
+ "client certificate request" (opitonal) - Client: Verifies server certificate + Check cryptographic parameters
- Client to Server: Sends secret key information (encrypted with server public key)
- Client to Server: (if requested by server) Sends client certificate
- Server: (if client cert. requested) Verifies the client cert.
- Client to Server: Client "finished"
- Server to Client: Server "finished"
- Bi-directional: Exchange messages (encrypted with shared secret key)
-
- 1 / 15
-