API Training
API Training
An API is a Software interface, a building block that works behind the scenes to connect
different applications and systems so they can share information.
Provisioning: Enterprises are responsible for a continuous sequence of API strategy, design,
creation, orchestration, protection, testing, deployment, promotion, and monitoring.
Continuous API management enables each of these steps with functionality that also addresses
security, scalability, and manageability concerns.
Key questions:
API Styles:
• Tunnel Style (SOAP – Simple Object Access Protocol): Tunnel APIs on calling functions
o Created in 2001 and tight to HTTP
o Uses WSDL
o Focus on function/Methods
o Build components (DLL, etc)
o Publish WSDL
o Code generate proxy class via WSDL
o Use proxy class in client
o Much used for legacy
• URI (CRUD – Create Read Update Delete): Simple way to invoke requests. It can be an
open door for hacking.
o Created in 1995
o Focus on Objectives/Entities
o Design public identifiers
o Design query rules
o Use HTTP as operations
• Hypermedia (REST – Representational Sate Transfer): Similar to URI but used rich
content types, hyperlinks, etc. to create interactions focused on tasks and not on objects
o Created in 2001
• Event Driven/Reactive: Includes Websocket. Transmit data between a client and server
with low overhead.
o Emphasis on event notification
o Asynchronous
• GraphQL: Allows clients to explicitly tell the API how to present the data without the
need to create a large collection of requests and responses
o Created by Facebook
• gRPC: language agnostic that require client and server to agree on the payload.
o Created by google
• Security layer
• Caching Layer
• Representation Layer
• Orchestration Layer
• Determine Goals
• Identify Users
• Design Interface
• Evaluate
• Implement
Terms:
Cross-site scripting:
• Loads malicious scripts into trusted websites to send users via the site
• Usually via browsing side scrip
Denail of Service:
MITM:
• Forces the users to execute unwanted actions on a WEB app that the user is
authenticated
Injection
Overflow
• Rate Limiting
o Prevent DoS
o Restrict number of requests based on IP, Identity and resouce
• Message Validation
o Prevent Injection
o Validates incoming and outgoing messages
o Schema validation can be performed after message is received
• Encryption & Signing
o Prevents Spoof and MITM
o Can be performed at transport level via TLS and/or message level via XML-
signature
• Access Control
o Restricts usage of APIs based on user identity
o Makes authentication and authorization
OAuth and Open ID provides more granularity of control to enable delegate authorization and
identity token management
Basic authentication the user and password are in request reader
Digest authentication Password can be encrypted, but server can downgrade to basic
OAuth 2.0
Industry standard authorization protocol that permits a user to grant an application access to a
protected resource without exposing the user`s password.
An OAuth access token is issued and accepted for user authorization at the API endpoint.
During the registration of an APP into an API, is important to define a Scope of authorized
actions.
Authorization Server can be internal or external, Like google, facebook, Linkdin, etc.
Credentials are kept between the Authorization Server and Resource owner (client)
OAuth2 can be used to login into external partners like google or facebook, but it CANNOT
be considered as an authentication protocol. They are delegated for login only.
• Authorization Code
o Used for Web Apps or app with a scope access defined to a resource on
behalf of an end user whose identity must remain private
o For this to work, the client exchanges the authorization code for a token
o Implementation is complex and needs upfront research and business cases
• Implicit
o Instead of issuing an authorization code for a token, the client app has a
predefined token
o The authorization server does not authenticate the client
o It is optimized for Java Scripts applications
o Recommended for internal applications
o Not recommended for external apps
• Resource Owner Password Credentials
o To be used ONLY when there is a high degree of trust between the
resource owner and the client application
o Recommended to be used only when all other options are not available
o Weakest option against hackers
o Credentials are provided only once
• Client Credentials
o Used when client is working on its own behalf
o Use cases are applications that does not require interactions with the end
user
o Best for Daemon, command line interactions and IOTs
Best used with repeatable deployment tools for APIs with OAuth2.0 Too complex to make it
isolated.
Tokens can contain authentication detail, but it is not defined and not required.
If requirement is mandatory to control API access, OAuth 2.0 is the best option
Solution is to have OpenID Connect since it applies OAuth to an identity resource, identity is a
set of attributes. With this, one person can have multiples identities.
An ID Token will be generated in addition to the access (authorization) token, and acts like an
encrypted fingerprint.
The authentication process validates messages that are also called “CLAIMS”. Additional
information can also be used can also be requested by the scope.
Every new request of an authenticated user can be validated by a userinfo endpoint within the
Authorization server. If the information cannot be validated, the request resource will not be
able to be fully delivered.
In traditional app, credential are stored in client side. They are usually stored in the web
message and are visible to the browser and can be decompiled.
Access control for API is to keep the credential always on the server side (Authorization and
resource), implement monitoring and detection and establish credentials during client hand
shake and registration
Best action is to apply certificate pinning (RFC 7469), Whitelist Redirect URI, Proof Key for Code
Exchange - PKCE (RFC 7636). Is a key line of defense to prevent hijacking a server.
OpenID Connect
OpenID connect flow is based on the OAuth2.0 authorization flow. It uses similar components
such as resource owner (end User), Client App, Authorization server and resource server.
The main difference is that in addition to the access token, the ID token is issued and used in
the authentication flow for the client app to retrieve resources on behalf of the resource
owner.
• Minimal
• Dynamic
Gets details about location of the OpenID provider, also know as a discovery request.
JWT has a header that specifies authorization and signatures, the payload that specifies
standard and custom claims and signature that elaborates the mechanism used to sign the
JWT.
JWT has some features that are promoting its usage. These are:
Key benefits are that it works based on claims and provide authentication and authorization. It
can be portable to be used anywhere and can be stored in the client. It provides message level
encryption and signing.
But JWT has issues and problems. Mains are the difficulty to revoke a token and its
management, the security of the token and overhead and performance.
1- Job is signed it verifies the integrity of the claims contained within the JWT
2- Encryption is set and will hide all the claims from parties not set in the token
a. After encrypted, the token becomes a payload of the JWE object
b. Encryption is set using PKI structure
3- Object is signed with the private key of the request server
4- Object is encrypted with the public key of the recipient or with a shared secret
5- Uses the defined algorithm for effective encryption
1- The message is decrypted using the authorization server private key or the stablished
secret key
2- The extracted payload is passed as a signed job and verified against the requester
public key
A JTI (JSON Token Identifier) can be used to avoid for been replay.
A refresh token can be set to revalidate the original token. It can be set with a limit of times it
can be executed and with a time limit for the access token to be used.
JWT vs SAML
JWT is simetrical signed using HMAC
SMAL 2.0 and 1.1 is more complex and is relies in PKI only
JWT has a much less verbosity, making it better for HTTPS signing apps than SAML
In Stateful condition, the server must maintain apps state to support it when tokens are in use
and with SAML. Using JWT state of the application is not needed. The resource server validates
the client token against it private key.