Slide 1

Slide 1 text

Authentication & Authorization APIs Consuming APIs like a pro

Slide 2

Slide 2 text

Clifford Ouma Twitter: @clifford_ouma LinkedIn: Clifford Ouma Who I am Postman Student Leader Moi University

Slide 3

Slide 3 text

go.postman.co/build Understanding more about you

Slide 4

Slide 4 text

Mission You've been hired by a professional music blogger to create a workflow that helps them discover new music. You'll use the Spotify Web API to let the blogger search for songs they like and find similar music!

Slide 5

Slide 5 text

What you will learn go.postman.co/build Making API requests with Auth Calling a real-world REST API Chaining multiple API calls to build a workflow Visualizing response data

Slide 6

Slide 6 text

What is a workflow? And why do we need it?

Slide 7

Slide 7 text

Introducing: Workflows Authentication and Authorization Workflows are a chain of requests that execute in a particular order.

Slide 8

Slide 8 text

Introducing: Workflows Authentication and Authorization Workflows are a chain of requests that execute in a particular order. Requests are dependent on one another

Slide 9

Slide 9 text

Introducing: Workflows Authentication and Authorization Workflows are a chain of requests that execute in a particular order. Requests are dependent on one another Can be executed in different sequences

Slide 10

Slide 10 text

What is Auth? And why do APIs use it?

Slide 11

Slide 11 text

Introducing: Auth Authentication and Authorization Authentication = verifying identity

Slide 12

Slide 12 text

Introducing: Auth Authentication and Authorization Authentication = verifying identity Authorization = granting permissions

Slide 13

Slide 13 text

Introducing: Auth Authentication and Authorization Authentication = verifying identity Authorization = granting permissions Both are the first line of defense for the API

Slide 14

Slide 14 text

Authentication vs Authorization Authentication identifies that you are who you say you are. E.g Twitter verification

Slide 15

Slide 15 text

Authentication vs Authorization Authentication identifies that you are who you say you are. E.g Twitter verification Authorization verifies what permissions you have. E.g Restricted areas

Slide 16

Slide 16 text

Types of Auth in APIs A brief history

Slide 17

Slide 17 text

Basic Auth Simplest form of auth Uses email and password to verify users You have to trust the API hashes your password Requires using HTTPS connection for security

Slide 18

Slide 18 text

API Keys Your invitation to use the API API keys are alphanumeric strings that provide basic access to the API’s services and data. Provided by API upon signup Allow developers to impose rate limits and revoke access in a ToS violation. a4db08b7-5729-4ba9-8c08-f2df493465a1

Slide 19

Slide 19 text

OAuth: Where the Magic Happens

Slide 20

Slide 20 text

OAuth(Open Authorization) OAuth gets access to protected data Sophisticated and uses tokens and ID to authorize. But access is scoped There are 2 versions: OAuth1 OAuth2.0

Slide 21

Slide 21 text

OAuth: A valet key

Slide 22

Slide 22 text

Key has limited access to the car You give valet the key Takeaways from the valet scenario

Slide 23

Slide 23 text

Do the OAuth Dance 🕺🏽 Resource owner (User) Client (Application ) 1. Authorization Request “Can I view your Google contacts?” 2. Authorization Grant Code “OK!” Authorization server Resource server Authorization code grant type

Slide 24

Slide 24 text

Do the OAuth Dance 🕺🏽 Resource owner (User) Client (Application ) 1. Authorization Request 2. Authorization Grant Code 3. Authorization Grant Code Authorization server Resource server “Please give me an access token” 4. Access Token “Here you go” Authorization code grant type

Slide 25

Slide 25 text

Do the OAuth Dance 🕺🏽 Resource owner (User) Client (Application ) 1. Authorization Request 2. Authorization Grant Code 3. Authorization Grant Code Authorization server Resource server 4. Access Token 4. Protected Resource 5. Access Token “Please give me the user’s contacts” “Here you go” Authorization code grant type

Slide 26

Slide 26 text

Do the OAuth Dance 🕺🏽 Grant types Grant Type Optimization When to Use Authorization Code Server + Web/Mobile For apps involving a backend (server) that can hide a client secret

Slide 27

Slide 27 text

Do the OAuth Dance 🕺🏽 Grant types Grant Type Optimization When to Use Authorization Code Server + Web/Mobile For apps involving a backend (server) that can hide a client secret Authorization Code with PKCE Web, Mobile Single-Page apps and native apps, where client secret cannot be hidden from public

Slide 28

Slide 28 text

Do the OAuth Dance 🕺🏽 Grant types Grant Type Optimization When to Use Authorization Code Server + Web/Mobile For apps involving a backend (server) that can hide a client secret Authorization Code with PKCE Web, Mobile Single-Page apps and native apps, where client secret cannot be hidden from public Password 1st Party Apps For security reasons, this should only be used with apps made by the service itself (1st party apps)

Slide 29

Slide 29 text

Do the OAuth Dance 🕺🏽 Grant types Grant Type Optimization When to Use Authorization Code Server + Web/Mobile For apps involving a backend (server) that can hide a client secret Authorization Code with PKCE Web, Mobile Single-Page apps and native apps, where client secret cannot be hidden from public Password 1st Party Apps For security reasons, this should only be used with apps made by the service itself (1st party apps) Client Credentials Server-to- server For application-to-application communications when a user is not present in the workflow and the client must authenticate itself

Slide 30

Slide 30 text

Do the OAuth Dance 🕺🏽 Grant types Grant Type Optimization When to Use Authorization Code Server + Web/Mobile For apps involving a backend (server) that can hide a client secret Authorization Code with PKCE Web, Mobile Single-Page apps and native apps, where client secret cannot be hidden from public Password 1st Party Apps For security reasons, this should only be used with apps made by the service itself (1st party apps) Client Credentials Server-to- server For application-to-application communications when a user is not present in the workflow and the client must authenticate itself Implicit Legacy Now prefer use of Authorization Code with PKCE for frontend-only apps.

Slide 31

Slide 31 text

Do the OAuth Dance (in Postman) Enter grant type and credentials Get access token Postman simplifies this process 1. 2.

Slide 32

Slide 32 text

What does this have to do with workflows? Almost every API you come in contact with will have some form of authentication and/or authorization. This information is imperative to creating today’s workflow (and any other workflows or applications you create!)

Slide 33

Slide 33 text

Building our Workflow The Spotify Recommendation Flow

Slide 34

Slide 34 text

What we’re gonna do Spotify Song Recommendation Workflow The Spotify API OAuth 2 Postman You've been hired by a busy music blogger to create a workflow that helps them discover new music. You'll use the Spotify Web API to let the blogger search for songs they like and find similar music! In this exercise we will be using:

Slide 35

Slide 35 text

Workflow Get access token (OAuth) Get track id Get track recommendations

Slide 36

Slide 36 text

Your turn! Fork this collection Follow the instructions in “your turn!” The blogger wants more accurate song recommendations based on artists they like! Build a workflow that allows the blogger to enter three artists to generate 5 song recommendations Getting started 1. 2.

Slide 37

Slide 37 text

Going further Create a playlist of an authenticated user’s most-played songs Create a playlist of songs with no words (for studying!) Finds recommendations based on a user’s currently playing track ...Your idea here! What workflows could you make? Explore the Spotify API reference

Slide 38

Slide 38 text

Continue Learning APIs as a Student Expert Student Expert certification indicates that you are proficient in the essential skills involved in building and testing API requests in Postman, including: Sending more sophisticated requests in Postman. Editing documentation for a collection. Writing basic test scripts. Running collections, passing data between requests, and scripting request execution order. Have the option to become a Student Leader in your community

Slide 39

Slide 39 text

Postman Student Expert Apply here: https://bit.ly/postman-student-program

Slide 40

Slide 40 text

Q&A