Jeremy's IT Lab
Day 61 Part 2Automation

REST API Authentication

29m7 chapters119 cues13 cards
Day 61 Part 2YT: bmqr_xpt6sc
00:00 / 29:15

Synchronized Transcript

119 cues indexed • Click dialogue or words to jump
Jeremy

Hi from Tokyo Japan and welcome to Jeremy's IT Lab in this video we're going to cover rest API authentication we've already covered the basics of rest apis.

Jeremy

But Cisco recently added authentication to the list of things you need to know about rest for the CCNA exam apis give access to an application and its data.

Jeremy

So security should always be a major concern when designing and using apis in this video we'll examine some common methods of rest API authentication.

Jeremy

But before we get started let me take a minute to shill my books acing the CCNA exam volumes 1 and two these books are up toate covering everything you need for the latest version of the exam uh rest API authentication.

Jeremy

For example is covered in chapter 23 of volume 2 I highly recommend using books in combination with the video course and if you want my books you can get them at the link on the screen.

Jeremy

Now or on Amazon now let's get started so what are we going to cover in this video first I'll introduce the concept of rest API authentication in general including why it's.

Jeremy

So important then for the rest of the video we'll cover four common types of rest authentication basic authentication Bearer authentication API key authentication and.

Jeremy

Finally ooth 2.0 we'll outline how each of these methods works and their advantages and dis dis advantages so that's the plan for today now let's learn about rest API authentication hopefully you already know this definition from the security section of the course.

Jeremy

But authentication is the process of validating the identity of a user or system to ensure legitimate access to resources in the case of an API the resource is the application and its data in many cases these resources should be protected.

Jeremy

But without authentication unauthorized users can send a requests potentially accessing sensitive data or modifying the the application.

Jeremy

For example here we have an application and some data the API serves as an interface allowing other apps to use the application or to access its data without authentication.

Jeremy

If a malicious user sends an API call also called an API request the API will accept the request and provide the requested data it's worth noting that some apis are intentionally open and don't require authentication these apis typically provide publicly available data.

Jeremy

That doesn't require security protection but for many apis that isn't the case and security is a major concern when the malicious user makes the API call the API should authenticate the user asking who are you.

Jeremy

If the authentication process fails the request is denied and the user doesn't get access to the data implementing a reliable authentication method like like.

Jeremy

This is essential for protecting applications and data that aren't meant to be publicly available and in addition to security concerns many apis track usage for analytics and billing purposes.

Jeremy

For example charging customers according to how much they use the API is a common practice a great example is the chat GPT API many AI applications use chat GPT behind the scenes and open AI charges businesses based on token usage basically.

Jeremy

A token is a chunk of text either input or output and this means companies pay more as they send larger or more frequent requests to the API.

Jeremy

So to summarize the previous slide when working with rest apis authentication is crucial for verifying a client's identity and securing access to to resources rest apis use various types of authentication to achieve this and we'll cover some key ones in this video.

Jeremy

These Authentication types are also called authentication methods or authentication schemes those are the more technical terms in this video we're going to cover four of them.

Jeremy

The first method is basic authentication as the name suggests this is the simplest form of rest authentication it sends a username and password in every request encoded in base 64 format note that encoding is not the same as encryption I'll explain that in the.

Jeremy

Next slide next we have Bearer authentication this method uses a token called a bearer token included as an HTTP header in the request to verify the client's identity this method is quite common in modern apis The Client.

Jeremy

First obtains a token and then includes it in requests after after that another common method is API key authentication this requires a unique key which is typically included as an HTTP header like the bearer token the API ke acts as a unique identifier for.

Jeremy

The client and is useful for tracking usage finally we have ooth 2.0 this is a more advanced and secure authentication framework that grants access using access access tokens ooth 2.0 is widely used for delegated access and thirdparty authentication.

Jeremy

I'll break down what those terms mean when we cover ooth 2.0 in detail but if you've ever seen the login with Google option on a website that's OA to .0 each of these methods has its own advantages and use cases.

Jeremy

Now let's look at them one by one we'll start with basic authentication which authenticates using a username and password in the HTTP headers of each API request before we dive deeper into basic authentication.

Jeremy

Let's break down the structure of an HTTP message so you can see where authentication fits in it begins with What's called the start line which includes includes three pieces of information the HTTP method which is post in this case the URL which is API slv1.

Jeremy

ACL rules and the HTTP version which is two in this case the post method is typically used for a create operation think back to the CRUD operations create read update delete we covered in the previous video on rest.

Jeremy

So this HTTP message is probably a request to create something on the server next we have the headers these provide metadata about the request such as authentication details content type and information about the client making the the request often there.

Jeremy

Are several headers there are four in this case the headers are followed by a blank line and then there is the message body the actual contents of the message.

Jeremy

This is the HTTP message which would then be encapsulated in a TCP segment to be sent over the network this message is using basic authentication can you find it it's this line right here it uses the authorization header.

Jeremy

But the real purpose is to authenticate the request and then that authentication can be used to provide proper authorization now that we've identified where the basic authentication occurs in the HTTP headers of the API request.

Jeremy

Let's look a bit deeper at basic authentication as I said basic Authentication includes a username and password in the HTTP headers these credentials are encoded in base 64 format.

Jeremy

But not encrypted that's an important distinction base 64 is an encoding scheme which is simply a way of representing data and unlike encryption it is not secure and can be easily decoded.

Jeremy

So although I've been referring to HTTP you really should be using HTTPS with your rest apis for security HTTPS is HTTP plus TLS transport layer security which provides robust encryption and security the username and password used.

Jeremy

For basic authentication are sent in the format username colon password encoded in base 64 for example username Jeremy and password CCNA would be sent as this string of string of characters.

Jeremy

If you're curious you can visit this URL base64decode org to encode and decode base base 64 so let's see how basic authentication Works in action on the right here we have the rest server with an API allowing access to its data and on the left we have a client.

Jeremy

App that wants to access the data it sends an API call including the authorization header for authentication notice the password is encoded in base 64.

Jeremy

That's username Jeremy and password CCNA the authentication succeeds so the server grants the request and responds with the data so it's that simple a username and password are included with each request and.

Jeremy

If they're correct authentication authentication succeeds now that we've seen how basic authentication Works let's consider the advantages and disadvantages honestly the main advantage is that it's simple and easy to implement just a username and password.

Jeremy

But since those credentials are sent in every request attackers could steal them if the connection is isn't properly secured but really that applies for any authentication method HTTPS is essential.

Jeremy

When communicating over the modern Internet you shouldn't use regular regular HTTP but even if using HTTPS for encryption relying solely on a username and password combination isn't particularly secure.

Jeremy

If an attacker gets access to the credentials whether through social engineering or another attack they get access to the API so that's basic Authentication.

Jeremy

Let's move on to the next method next we'll look at Bearer authentication which is a form of token-based authentication and uses a token instead of a username and password in Bearer authentication The Client.

Jeremy

First obtains a token by authenticating with an authorization server often just called an o server this is typically different from the server actually hosting the resource the client wants to access note that authenticating with the off server can be done using basic authentication or.

Jeremy

Another authentication method this step is separate from the actual API request to the resource server then after the client gets the token for each API request the client includes the token in the HTTP authorization header like we saw before.

Jeremy

For example it will look something like this authorization Bearer and then the token let's see how it works notice I'm showing two servers.

Jeremy

Now one is the o server which generates the token and then the resource server which hosts whatever resource the client wants to access so to begin the client requests a token from the o server and.

Jeremy

If successful the server grants the client a a token then when the client sends an API call to the resource server it includes the token in the call.

Jeremy

And then the resource server responds either with the requested resource or a message indicating the server did what was requested so.

Jeremy

That's basically how Bearer authentication works the term Bearer means that anyone who possesses the token can use it this means that.

Jeremy

If an attacker steals the token they can make requests API calls as if they were the legitimate user this is clearly a security problem so to mitigate against this tokens usually expire after a set period of time the expiration time depends on the API security needs some tokens.

Jeremy

Expire in 15 minutes to reduce risk While others last weeks or months for conveni venience especially in low security environments okay.

Jeremy

Let's summarize by considering some advantages and disadvantages of Bearer authentication first off it's more secure than basic authentication because there's no need to transmit the same username and password for every single API call The Tokens that are used instead expire.

Jeremy

So a stolen token will only be temporarily valid but still it's worth mentioning as a disadvantage that if the token is stolen the attacker can still access the API until the token expires and since tokens need to be refreshed periodically it adds some extra complexity.

Jeremy

When implementing Bearer authentication compared to basic authentication that's not a problem for Network Engineers but for the programmers who build these apis it's worth worth considering and.

Jeremy

Finally just like basic authentication it should only be used with with HTTPS if the token is sent in clear text no encryption it simply isn't secure you need HTTP PS.

Jeremy

When communicating over the modern modern Internet while Bearer tokens are commonly used for user authentication in apis some apis use a simpler method which we'll cover.

Jeremy

Next next up is API key authentication which uses a static key issued by the API provider the client uses this key in each API call for authentication the main difference between a barrer token and a key is that unlike.

Jeremy

Barer tokens the API key is static it doesn't expire automatically so it remains valid until revoked API keys can be sent to the server in a few ways the recommended way is to include the key in the HTTP authorization header as we saw in basic and Bearer authentication.

Jeremy

But you can also include the key in the URL in the start line of the HTTP request by adding a parameter to the URL but this is not recommended for several reasons one being that since URLs are often logged by web servers proxies and browsers API Keys included.

Jeremy

In URLs can be exposed in logs making them vulnerable to attackers and a third option is to send the API key as a cookie which is sometimes used for browser-based apis.

Jeremy

But in any case the recommended method is to include the key in the authorization header let's see what it looks like it's quite simple the client sends an API call to the server hosting the resource wants to access and the client includes the API key in the authorization header of.

Jeremy

The HTTP message assuming the key was valid the server then sends its response okay now that we've seen how it works let's consider a couple of advantages and advantages and disadvantages one advantage is that it's easier to implement than Bearer authentication.

Jeremy

And API key authentication is good for tracking usage the API provider can assign a unique key to each customer and then easily track each customer's usage by tracking the key used in each API call.

Jeremy

Because of this API keys are often used in cloud services and third-party apis if you're wondering what a thirdparty API is think of a developer that builds a chatbot app that uses chat GPT the end users are.

Jeremy

The first party the developer creating the chatbot app is the second party but instead of generating responses itself the app calls open ai's API to get responses from chat GPT since open AI is external to both the users and the app developer it's the.

Jeremy

Third party in this interaction hopefully that makes sense now let's look at a couple of disadvantages one problem is that if stolen the key grants full access until revoked it doesn't automatically expire.

Jeremy

So API Keys must be rotated manually to maintain security whereas the tokens used in Bearer Authentication expire automatically.

Jeremy

Okay that's all for API key authentication finally we move on to ooth 2.0 it's a secure authentication framework that is widely used in modern web applications its overall purpose is different from the other methods we've looked at in that it provides access delegation granting thirdparty.

Jeremy

Applications limited access to resources on behalf of the resources owner the main benefit is that there is no need to share the resource owner's credentials with the.

Jeremy

Third party for example when you use login with Google on a website the website never sees your Google password instead Google confirms your identity and grants access only to approved information.

Jeremy

Let's look at some examples of ooth 2.0 the first is what I just mentioned logging in with Google many websites and apps offer the option to log in using your Google account the thirdparty website or app is granted access to some of your Google accounts information without actually.

Jeremy

Getting access to your accounts credentials connecting apps to social media accounts is another example many apps can be connected to Instagram Facebook LinkedIn Etc ooth 2.0 lets these apps access your social media account for specific tasks like posting on your behalf without.

Jeremy

Revealing your login login credentials calendar integration is one more example a thirdparty tool like a scheduling app can be given access to your Google calendar to check availability and schedule meetings these are all common examples of ooth.

Jeremy

2.0 now let's see how it actually works there are four main parties involved first is the resource owner the account owner granting access to their data using the Google Calendar integration example.

Jeremy

This is the owner of the Google account next is The Client app the thirdparty application application requesting access to your Google data like a scheduling tool accessing your calendar then there's the off server this server issues access tokens granting limited access.

Jeremy

To your Google account after receiving user approval in this example this is Google's ooth service finally there is the resource server the server that hosts the protected resource in this example it's the server hosting the Google calendar data that the.

Jeremy

Client app wants to access now let's see ooth 2.0 in action the overall process consists of six main steps first The Client app requests authorization from the resource owner in our example this could be a scheduling app requesting access to your Google calendar.

Jeremy

Next the resource owner which is you the account owner grants authorization by logging into your Google account and giving permission for the scheduling app to access your calendar data once permission is granted The Client app exchanges this authorization grant for an access token from.

Jeremy

The off server which in this case is Google's ooth service the o server then issues an access token to The Client app this token acts as a temporary key that allows the app to request resources on your your behalf.

Jeremy

Now that the client app has a token it includes the token in an API request to the resource server which hosts the actual data in this case your Google calendar data.

Jeremy

Finally the resource server validates the access token and provides the requested resource back to the client app if the token is valid and the app has the correct permissions it will receive the data it needs the key part of ooth 2.0 is the access token issued in step four.

Jeremy

It functions like the tokens we saw in Bearer authentication it grants access to the specified resource within the allowed scope for example readon access and just as in Bearer authentication access tokens expire after a short period which helps improve security.

Jeremy

But instead of requiring the user to log in again every single time the access token expires ooff 2.0 uses refresh tokens granted by the off server which allow The Client app to request a new access token without user interaction this way the app can maintain access.

Jeremy

Over an extended period of time without constantly requiring the user to log in so that's ooth 2.0 it allows thirdparty apps to securely access a user's data without exposing their credentials and while allowing users to control what information is shared.

Jeremy

That's why ooth 2.0 is so widely used in modern web applications by the way ooth 2.0 is defined in RFC 6749 which you can access from this link here or just Google search for RFC 6749 diving into rfc's isn't expected for the CCNA.

Jeremy

Exam but if you're curious to learn more about oaf 2.0 it's worth checking checking out all right let's wrap things up with a quick summary of what we covered in this video before moving on to the quiz rest API authentication ensures that only authorized users or systems.

Jeremy

Can access an API without it anyone could send API requests potentially exposing or modifying sensitive data we looked at four types of rest API Authentication methods basic authentication uses a username and password encoded in base 64.

Jeremy

But it's not encrypted so it must be used with HTTPS for security actually that statement really applies to all of these authentication methods in the modern Internet you should always use HTTPS not regular HTTP Bearer authentication is a step up in security using.

Jeremy

A token issued by an authorization server instead of sending a username and password in request tokens expire after a short time which increases security.

Jeremy

But they can still be stolen if not protected with HTTPS next API key authentication Works similarly but uses a static key issued by the API provider it's good for tracking API usage.

Jeremy

So it's commonly used by cloud service providers and thirdparty thirdparty apis it's easier to implement than Bearer authentication but it's considered less secure.

Jeremy

Because because stolen Keys remain valid until manually revoked they don't automatically expire finally ooth 2.0 is a framework for Access delegation allowing thirdparty applications limited access to a user's resources without sharing login credentials it.

Jeremy

Relies on access tokens that can be refreshed with a refresh token allowing continued access without user reauthentication oo 2.0 involves four key parties the resource owner.

Jeremy

For example the owner of the Google account The Client app the app that requests access to the account's resources the authorization server which grants The Client app a token to provide limited access to the requested resource and.

Jeremy

Finally the resource server the server that hosts the protected resource for example the Google accounts information okay that's what we covered in this video.

Jeremy

Now let's move on to a quick quiz to test your understanding here's quiz question one which of the following rest authentication methods involve an off server issuing tokens select two pause the video.

Jeremy

Now to think about your answers okay the answers are A and B ooth 2.0 and Bearer authentication.

Jeremy

Here's the diagram I showed for oo 2.0 and here's the diagram for Bearer authentication basic Authentication doesn't involve an off server it just uses simple username and password authentication and neither does API key authentication which.

Jeremy

Uses a static key okay let's go to the next question here's question two which of the following best describes how oof 2.0 improves security pause the video.

Jeremy

Now to think about your answer okay the answer is B it allows third-party apps to access resources without exposing user credentials.

Jeremy

Here's the diagram once again instead of using the resource owner's credentials for authentication The Client app receives an access token from the off server in step four which allows it to authenticate with the resource server in step five.

Jeremy

And then access the resource okay let's go to the next question here's question three which of the following statements are true select three pause the video.

Jeremy

Now to think about your answers okay the answers are b c and e b is correct because Bearer authentication does require a token the term Bearer refers to this Bearer token C is correct.

Jeremy

Because ooth 2.0 enables access delegation as we covered in the previous quiz question and E is correct because instead of requiring user authentication every time the access token expires a refresh token can be used to automatically obtain a new access.

Jeremy

Access token a is incorrect because API keys do not expire automatically for this reason they are considered less secure than tokens D is incorrect.

Jeremy

Because basic authentication doesn't use encryption instead the username and password are encoded in base 64 format which is easily reversible.

Jeremy

Finally f is incorrect because API Keys should not be included in URLs instead they should be included in the HTTP authorization header as.

Jeremy

This is more more secure okay that's all for the quiz and that's all for this video on rest API authentication we covered four kinds basic authentication Bearer authentication API key authentication and oof 2.0 there are other rest authentication methods.

Jeremy

Out there but these are the four I recommend knowing for the CCNA exam I hope you found this video helpful thanks for watching before finishing this video.

Jeremy

Let me thank my jcmp level channel members who support me through YouTube channel membership to become a member please click the join button under the video thanks to yonathan makura George Gustavo maedo Marcel Lord dragos Hera Zak sha mayor Salman Vel 194 Mark Jackson.

Jeremy

Bold 1 c1u Gerald Guam Hector Hernandez arpad KZ five feat oad Daniel Brown Jose Alvarez jusan yavuz Samuel Tavarez Kevin Hayes Brian Grant giori gev Adison Pereira madmar 50484 Alexandre Straton.

Jeremy

Dmj 2 Steve Cox Jasper Yim Pedro Hartman tricky Mickey 123456 Ivano capuano Jefferson steel Flex toxic cenan cinar Wilmer Romero Daniel Andrade dragos George Philip yanovich Trevor Goldman Sunny igu hello.

Jeremy

BPDU edificare mikal chopski hon jabal Puri darush D Juan Morales Gonzalo Nicolas doomed Soul Julio Maya eraso Hashem rodef Anand Aban Clyde Muro bindo Orlando Flores Adrien.

Jeremy

Martinez MD Daniel Vitz gg7 Ry Enriquez Tobe hin Vic MDS Electro naria G Gant Raymond Kirby Henrietta SAU yuk shika Uma Shankar Sharma Ali Rizza beler sebz James Corley Alexi usov.

Jeremy

KitKat excelus Captain Flamingo Tian coni to be like our superheroes Muhammad Balta Tazo gonad opero Muhammad Gideon ibikunle Matel Falcone omole Seline Jean Rie good Zack Ross I'm me 87 karasan.

Jeremy

JD kend onid and Johannes bu sorry if I pronounced your name incorrectly but thank you so much for your support thanks to you and my other supporters I am able to make these videos and release them for free on YouTube.

Jeremy

So I really appreciate the support another great way to support the channel is to like the video leave a comment subscribe and most importantly share this video with others.

Jeremy

So if this video was helpful I'd appreciate it if you did any of those thanks for watching [Music].

Keyboard shortcuts

Shortcuts are ignored while you are typing in a search box, note field, or the scratchpad.

Playback

SpaceK
Play or pause
←→
Seek 5 seconds
JL
Seek 10 seconds
C
Toggle in-video captions

Scrubber (when focused)

←→
Seek 5 seconds
Shift←/→
Seek 10 seconds
Page UpPage Down
Seek 30 seconds
HomeEnd
Jump to start or end

Flashcards

Space
Reveal the answer
1234
Grade Again / Hard / Good / Easy

Navigation

←→
Move between study-mode tabs
HomeEnd
First or last study-mode tab
?
Open or close this sheet