1
1

00:00:00,600  -->  00:00:01,530
<v ->REST.</v>
2

2

00:00:01,530  -->  00:00:04,230
In this lesson we're going to talk about REST,
3

3

00:00:04,230  -->  00:00:06,870
the Representational State Transfer.
4

4

00:00:06,870  -->  00:00:09,450
Now, REST is a software architectural style
5

5

00:00:09,450  -->  00:00:10,830
that defines a set of constraints
6

6

00:00:10,830  -->  00:00:14,040
to be used for creating web application services.
7

7

00:00:14,040  -->  00:00:15,270
When we talk about REST
8

8

00:00:15,270  -->  00:00:18,120
you also hear it referred to as RESTful APIs
9

9

00:00:18,120  -->  00:00:20,340
and these are a looser architectural framework
10

10

00:00:20,340  -->  00:00:22,920
than SOAP's tightly specified protocol.
11

11

00:00:22,920  -->  00:00:23,753
Now, if you remember
12

12

00:00:23,753  -->  00:00:26,160
we talked about SOAP used XML based messages.
13

13

00:00:26,160  -->  00:00:28,500
Well, REST has a lot more options.
14

14

00:00:28,500  -->  00:00:32,550
REST is going to support HTTP, XML, CSV
15

15

00:00:32,550  -->  00:00:34,440
which is comma separated value format
16

16

00:00:34,440  -->  00:00:36,570
or even JSON messages.
17

17

00:00:36,570  -->  00:00:37,620
All of these are messages
18

18

00:00:37,620  -->  00:00:40,200
that can be accepted and passed over REST
19

19

00:00:40,200  -->  00:00:42,930
instead of just relying on a properly formatted XML document
20

20

00:00:42,930  -->  00:00:44,460
like SOAP does.
21

21

00:00:44,460  -->  00:00:46,980
Now, let me give you an example of how this all works.
22

22

00:00:46,980  -->  00:00:49,380
If you wanted to go to my website and log into your account
23

23

00:00:49,380  -->  00:00:51,960
you would go to the domain name of diontraining.com
24

24

00:00:51,960  -->  00:00:54,090
and then go to the resource myaccount.
25

25

00:00:54,090  -->  00:00:57,060
It would look like diontraining.com/myaccount.
26

26

00:00:57,060  -->  00:01:00,660
Now, when you do this it performs an HTTP get request
27

27

00:01:00,660  -->  00:01:03,570
to receive a list of all of the courses you're enrolled in.
28

28

00:01:03,570  -->  00:01:05,610
It's also going to give you your progress or percent complete
29

29

00:01:05,610  -->  00:01:06,750
in the courses you're enrolled in
30

30

00:01:06,750  -->  00:01:09,090
and some other basic profile information.
31

31

00:01:09,090  -->  00:01:09,923
Now, on the other hand,
32

32

00:01:09,923  -->  00:01:11,310
when you start taking a quiz on my site
33

33

00:01:11,310  -->  00:01:13,230
and you click the submit button at the end,
34

34

00:01:13,230  -->  00:01:14,580
it's going to take that information
35

35

00:01:14,580  -->  00:01:16,560
as part of a RESTful API command
36

36

00:01:16,560  -->  00:01:20,790
and use the HTTP post command to send that to my server.
37

37

00:01:20,790  -->  00:01:22,350
Now, as we go through this lesson
38

38

00:01:22,350  -->  00:01:23,670
we're going to talk a little bit more
39

39

00:01:23,670  -->  00:01:25,677
about REST and RESTful APIs,
40

40

00:01:25,677  -->  00:01:26,880
and we're specifically going to talk
41

41

00:01:26,880  -->  00:01:28,860
about three major concepts.
42

42

00:01:28,860  -->  00:01:30,300
We're going to talk about OAuth,
43

43

00:01:30,300  -->  00:01:33,180
we're going to talk about OpenID Connect, or OIDC
44

44

00:01:33,180  -->  00:01:36,540
and we're going to talk about JSON Web Tokens or JWT.
45

45

00:01:36,540  -->  00:01:38,130
Now, when we talk about OAuth,
46

46

00:01:38,130  -->  00:01:40,290
this is a delegated authorization framework
47

47

00:01:40,290  -->  00:01:43,050
for RESTful APIs that enables applications
48

48

00:01:43,050  -->  00:01:46,080
to obtain limited access, also known as scopes
49

49

00:01:46,080  -->  00:01:49,920
to a user's data without giving away a user's password.
50

50

00:01:49,920  -->  00:01:51,570
Now, when you're dealing with OAuth,
51

51

00:01:51,570  -->  00:01:54,690
this is a form of authentication and authorization
52

52

00:01:54,690  -->  00:01:56,880
using this RESTful API.
53

53

00:01:56,880  -->  00:01:58,800
Now, when we talk about OAuth,
54

54

00:01:58,800  -->  00:02:01,830
this stands for the open authorization 2 protocol.
55

55

00:02:01,830  -->  00:02:03,240
It's version 2.
56

56

00:02:03,240  -->  00:02:04,860
Now, OAuth comes in two versions.
57

57

00:02:04,860  -->  00:02:05,850
There's version 1
58

58

00:02:05,850  -->  00:02:07,650
which is not commonly implemented anymore,
59

59

00:02:07,650  -->  00:02:09,510
and there's version 2.
60

60

00:02:09,510  -->  00:02:10,620
Now, notice what I said there.
61

61

00:02:10,620  -->  00:02:11,640
It's called OAuth
62

62

00:02:11,640  -->  00:02:14,580
because it's the open authorization protocol.
63

63

00:02:14,580  -->  00:02:16,590
That means this is all about authorization,
64

64

00:02:16,590  -->  00:02:18,003
not authentication.
65

65

00:02:18,870  -->  00:02:20,250
Now, when you're using OAuth
66

66

00:02:20,250  -->  00:02:22,710
it's going to serve four types of parties.
67

67

00:02:22,710  -->  00:02:25,350
You have clients, you have resource owners,
68

68

00:02:25,350  -->  00:02:26,580
you have resource servers,
69

69

00:02:26,580  -->  00:02:28,140
and you have authorization servers.
70

70

00:02:28,140  -->  00:02:31,950
Again, OAuth is for authorization.
71

71

00:02:31,950  -->  00:02:33,180
When we talk about a client,
72

72

00:02:33,180  -->  00:02:36,750
these are applications that the user wants to access or use.
73

73

00:02:36,750  -->  00:02:38,220
When we talk about the resource owners,
74

74

00:02:38,220  -->  00:02:40,950
these are the end users who are being serviced.
75

75

00:02:40,950  -->  00:02:42,570
When we talk about the resource servers,
76

76

00:02:42,570  -->  00:02:44,850
these are the servers provided by a service
77

77

00:02:44,850  -->  00:02:46,740
that the user wants to access.
78

78

00:02:46,740  -->  00:02:48,387
And then we have the authorization server.
79

79

00:02:48,387  -->  00:02:51,030
When we talk about the authorization server,
80

80

00:02:51,030  -->  00:02:53,490
we're talking about servers owned by the identity provider
81

81

00:02:53,490  -->  00:02:55,080
or the IdP.
82

82

00:02:55,080  -->  00:02:57,420
Now, how does this all work in the real world?
83

83

00:02:57,420  -->  00:02:59,460
Well, let me give you an example here.
84

84

00:02:59,460  -->  00:03:01,620
Here on the screen you'll see three columns.
85

85

00:03:01,620  -->  00:03:03,840
We have the client, the authorization servers
86

86

00:03:03,840  -->  00:03:05,370
and the resource owners.
87

87

00:03:05,370  -->  00:03:06,900
Now, this example comes from Flickr,
88

88

00:03:06,900  -->  00:03:08,340
and this is assuming you're going to be using
89

89

00:03:08,340  -->  00:03:10,350
the Flickr OAuth service.
90

90

00:03:10,350  -->  00:03:12,630
This is their version of single sign on.
91

91

00:03:12,630  -->  00:03:14,400
Now, when I talk about a client here
92

92

00:03:14,400  -->  00:03:17,160
I'm not talking about a client as in an end user.
93

93

00:03:17,160  -->  00:03:19,470
Remember my definition I just used in OAuth.
94

94

00:03:19,470  -->  00:03:20,910
A client is an application
95

95

00:03:20,910  -->  00:03:23,130
that the user wants to access or use.
96

96

00:03:23,130  -->  00:03:25,500
So, let's assume that my website
97

97

00:03:25,500  -->  00:03:27,780
was going to use Flickr single sign on
98

98

00:03:27,780  -->  00:03:29,730
as a way for you to log into it.
99

99

00:03:29,730  -->  00:03:31,170
If you wanted to get into my website
100

100

00:03:31,170  -->  00:03:33,540
you would go to my website, the application,
101

101

00:03:33,540  -->  00:03:34,980
in this case, the client,
102

102

00:03:34,980  -->  00:03:36,180
you would click on the login button
103

103

00:03:36,180  -->  00:03:38,400
and select the logon with Flickr.
104

104

00:03:38,400  -->  00:03:41,460
If you do that, you are now requesting a token.
105

105

00:03:41,460  -->  00:03:42,450
At this point,
106

106

00:03:42,450  -->  00:03:45,390
my server is going to communicate to the authorization server,
107

107

00:03:45,390  -->  00:03:47,880
going from the client to the authorization server
108

108

00:03:47,880  -->  00:03:50,460
and we are going to request that token.
109

109

00:03:50,460  -->  00:03:51,293
At that point
110

110

00:03:51,293  -->  00:03:53,340
the authorization server should give us back that token.
111

111

00:03:53,340  -->  00:03:55,140
They're going to return it to us.
112

112

00:03:55,140  -->  00:03:56,700
Now that that's happened,
113

113

00:03:56,700  -->  00:03:58,320
we're going to direct the user
114

114

00:03:58,320  -->  00:04:00,570
to go to Flickr for authorization.
115

115

00:04:00,570  -->  00:04:02,700
So you're going to get sent over to Flickr
116

116

00:04:02,700  -->  00:04:04,260
and you're going to put in your username and password
117

117

00:04:04,260  -->  00:04:05,700
on the Flickr site.
118

118

00:04:05,700  -->  00:04:07,440
At that point, Flickr server,
119

119

00:04:07,440  -->  00:04:09,180
which again is the authorization server here
120

120

00:04:09,180  -->  00:04:12,090
is going to prompt the user to provide their authorization,
121

121

00:04:12,090  -->  00:04:13,740
their username and password.
122

122

00:04:13,740  -->  00:04:16,890
Now, if you have put in the right username and password
123

123

00:04:16,890  -->  00:04:18,750
the resource owners in this case,
124

124

00:04:18,750  -->  00:04:20,490
which is the end user wanting to be serviced,
125

125

00:04:20,490  -->  00:04:21,900
in this case, you,
126

126

00:04:21,900  -->  00:04:24,570
is going to authorize applications to have access.
127

127

00:04:24,570  -->  00:04:27,420
So, you're going to get a button that says from Flickr says,
128

128

00:04:27,420  -->  00:04:29,340
diontraining.com would like to allow you
129

129

00:04:29,340  -->  00:04:31,680
to log into their site using your Flickr account
130

130

00:04:31,680  -->  00:04:33,510
and you'll say yes or no.
131

131

00:04:33,510  -->  00:04:34,343
At that point
132

132

00:04:34,343  -->  00:04:36,600
you're going to be redirected back from Flickr server,
133

133

00:04:36,600  -->  00:04:38,970
the authorization servers, to the application,
134

134

00:04:38,970  -->  00:04:42,240
that game or website, in my case, my website
135

135

00:04:42,240  -->  00:04:45,300
and that way you're going to get this OAuth verifier sent over.
136

136

00:04:45,300  -->  00:04:48,450
Now, the client, again, my application
137

137

00:04:48,450  -->  00:04:51,120
which could be a game or my website or something like that
138

138

00:04:51,120  -->  00:04:54,840
is going to exchange the required token for an access token.
139

139

00:04:54,840  -->  00:04:56,610
Once we have that access token,
140

140

00:04:56,610  -->  00:04:59,160
we're going to grant that access token over to Flickr
141

141

00:04:59,160  -->  00:05:00,780
to their authorization servers
142

142

00:05:00,780  -->  00:05:02,490
and they're going to associate that with your account.
143

143

00:05:02,490  -->  00:05:04,050
Now, anytime you log in
144

144

00:05:04,050  -->  00:05:06,510
and try to log into my service or my application
145

145

00:05:06,510  -->  00:05:07,350
using Flickr,
146

146

00:05:07,350  -->  00:05:10,020
it's going to know what rights you have on my system.
147

147

00:05:10,020  -->  00:05:12,570
And at that point, you're going to have this OAuth token
148

148

00:05:12,570  -->  00:05:14,760
that's now going to allow you to have protected access
149

149

00:05:14,760  -->  00:05:15,720
to different resources,
150

150

00:05:15,720  -->  00:05:18,600
maybe videos or quizzes or lessons or whatever it is,
151

151

00:05:18,600  -->  00:05:20,760
and then I can send those over to you,
152

152

00:05:20,760  -->  00:05:23,250
the resource owner, being the end user.
153

153

00:05:23,250  -->  00:05:24,900
That's how this works.
154

154

00:05:24,900  -->  00:05:26,220
Now, this is a little bit different
155

155

00:05:26,220  -->  00:05:28,170
than what we talked about with SOAP and SAML,
156

156

00:05:28,170  -->  00:05:29,970
but it kind of uses the same concept
157

157

00:05:29,970  -->  00:05:32,730
because OAuth was based on those things.
158

158

00:05:32,730  -->  00:05:34,380
Now, when we talk about OAuth2
159

159

00:05:34,380  -->  00:05:36,510
it is vulnerable to some attacks.
160

160

00:05:36,510  -->  00:05:37,950
For instance, it is vulnerable
161

161

00:05:37,950  -->  00:05:40,290
to a cross-site request forgery attack,
162

162

00:05:40,290  -->  00:05:42,330
and also to open redirects.
163

163

00:05:42,330  -->  00:05:43,650
This is where the attacker is going to attempt
164

164

00:05:43,650  -->  00:05:46,050
to get you as the user to click on a link
165

165

00:05:46,050  -->  00:05:49,170
so your browser will perform the actions as that user
166

166

00:05:49,170  -->  00:05:50,400
using your credentials.
167

167

00:05:50,400  -->  00:05:52,170
And so you have to be careful of these things
168

168

00:05:52,170  -->  00:05:55,560
and we've talked before about cross-site request forgeries.
169

169

00:05:55,560  -->  00:05:59,340
Now, OAuth2 is explicitly designed to authorize claims
170

170

00:05:59,340  -->  00:06:02,250
and it is not used to authenticate users.
171

171

00:06:02,250  -->  00:06:05,340
Notice, this is an authorization protocol
172

172

00:06:05,340  -->  00:06:08,700
open authorization 2, that's what it stands for,
173

173

00:06:08,700  -->  00:06:09,600
so keep that in mind.
174

174

00:06:09,600  -->  00:06:14,190
OAuth is an authorization, not an authentication platform.
175

175

00:06:14,190  -->  00:06:15,930
Now, that means if you wanted to use it
176

176

00:06:15,930  -->  00:06:18,570
you have to have some way to authenticate users too.
177

177

00:06:18,570  -->  00:06:19,770
So how are you going to do that?
178

178

00:06:19,770  -->  00:06:22,770
Well, one of the most common ways is to use OIDC
179

179

00:06:22,770  -->  00:06:24,660
which is Open ID Connect.
180

180

00:06:24,660  -->  00:06:26,790
This is an authentication protocol
181

181

00:06:26,790  -->  00:06:29,730
and it can be implemented as special types of OAuth flows
182

182

00:06:29,730  -->  00:06:32,190
with precisely defined token fields.
183

183

00:06:32,190  -->  00:06:34,560
This will allow OAuth to be used for the authorization
184

184

00:06:34,560  -->  00:06:35,790
which is what it's good for
185

185

00:06:35,790  -->  00:06:38,250
and Open ID Connect can be used for authentication
186

186

00:06:38,250  -->  00:06:39,663
which is what it's best for.
187

187

00:06:40,500  -->  00:06:42,150
Now, I know I've been throwing around the words
188

188

00:06:42,150  -->  00:06:45,000
authorization and authentication over and over again
189

189

00:06:45,000  -->  00:06:47,220
in this lesson and some previous lessons,
190

190

00:06:47,220  -->  00:06:49,290
and if it's been a while since you've done security plus
191

191

00:06:49,290  -->  00:06:50,190
you may not remember
192

192

00:06:50,190  -->  00:06:51,750
what the difference is between these two.
193

193

00:06:51,750  -->  00:06:53,970
So let me just go and take a pause here
194

194

00:06:53,970  -->  00:06:56,220
and tell you exactly what that means.
195

195

00:06:56,220  -->  00:06:57,960
When we talk about authorization,
196

196

00:06:57,960  -->  00:07:00,420
this is the function of specifying access rights
197

197

00:07:00,420  -->  00:07:02,940
and privileges to certain resources.
198

198

00:07:02,940  -->  00:07:06,180
So if you wanted to access this video lesson in the course
199

199

00:07:06,180  -->  00:07:09,240
you need to have authorization to do that.
200

200

00:07:09,240  -->  00:07:11,550
For instance, if you wanted to take this Friday off of work
201

201

00:07:11,550  -->  00:07:14,550
you need authorization from your boss to not show up.
202

202

00:07:14,550  -->  00:07:16,410
They have to give you permission.
203

203

00:07:16,410  -->  00:07:18,810
Now, if we look at authentication,
204

204

00:07:18,810  -->  00:07:20,820
this is the process of verifying the identity
205

205

00:07:20,820  -->  00:07:22,200
of a person or device.
206

206

00:07:22,200  -->  00:07:23,850
So when you go to my website
207

207

00:07:23,850  -->  00:07:25,830
and you put in your username and password,
208

208

00:07:25,830  -->  00:07:27,660
that is authentication.
209

209

00:07:27,660  -->  00:07:30,270
Once you do that, and we know who you are
210

210

00:07:30,270  -->  00:07:32,460
we then check what courses you're in
211

211

00:07:32,460  -->  00:07:33,690
and based on those courses
212

212

00:07:33,690  -->  00:07:36,930
you have the authorization to access those videos.
213

213

00:07:36,930  -->  00:07:38,520
If you signed up for this course
214

214

00:07:38,520  -->  00:07:41,760
you have the authorization to watch the CySA videos
215

215

00:07:41,760  -->  00:07:43,680
but if you didn't sign up for the pen test plus course,
216

216

00:07:43,680  -->  00:07:46,260
you can't watch those, you're not authorized.
217

217

00:07:46,260  -->  00:07:47,730
But you use the same authentication
218

218

00:07:47,730  -->  00:07:49,470
to get into the system for both, right?
219

219

00:07:49,470  -->  00:07:51,030
And so that's the difference here.
220

220

00:07:51,030  -->  00:07:52,770
Now, when we talk about OAuth,
221

221

00:07:52,770  -->  00:07:54,330
this must be paired with another tool
222

222

00:07:54,330  -->  00:07:56,100
to perform that authentication
223

223

00:07:56,100  -->  00:07:58,920
because you have to have a way to verify that identity.
224

224

00:07:58,920  -->  00:08:01,740
And again, the best way to do that is with Open ID Connect.
225

225

00:08:01,740  -->  00:08:04,230
It's one of the most popular ways of doing this.
226

226

00:08:04,230  -->  00:08:05,730
Now, the third thing we need to talk about
227

227

00:08:05,730  -->  00:08:07,470
is JSON Web Tokens.
228

228

00:08:07,470  -->  00:08:10,800
Now, when you see JWT, which stands for JSON Web Tokens
229

229

00:08:10,800  -->  00:08:14,190
this is actually pronounced as Jot like J O T
230

230

00:08:14,190  -->  00:08:16,650
but it is JSON Web Tokens.
231

231

00:08:16,650  -->  00:08:19,350
Now, this is a token format that contains a header,
232

232

00:08:19,350  -->  00:08:20,970
a payload, and a signature
233

233

00:08:20,970  -->  00:08:23,820
in the form of a JavaScript Object Notation message,
234

234

00:08:23,820  -->  00:08:25,770
which is a JSON message.
235

235

00:08:25,770  -->  00:08:28,350
Now, when you think about a JSON Web Token
236

236

00:08:28,350  -->  00:08:30,600
I want you to think about OAuth.
237

237

00:08:30,600  -->  00:08:32,430
These are used to provide authorization
238

238

00:08:32,430  -->  00:08:35,160
and specify what access rights and privileges
239

239

00:08:35,160  -->  00:08:37,290
a user would have on a system.
240

240

00:08:37,290  -->  00:08:39,570
Again, these are a form of assertion
241

241

00:08:39,570  -->  00:08:41,670
that's being made about the person,
242

242

00:08:41,670  -->  00:08:44,370
and it assumes that person has already been authenticated.
243

243

00:08:44,370  -->  00:08:48,120
So if you're using a JSON token, you're making assertions.
244

244

00:08:48,120  -->  00:08:50,730
This, again, is the authorization piece
245

245

00:08:50,730  -->  00:08:53,250
not the authentication piece.
246

246

00:08:53,250  -->  00:08:55,620
Now, if you want to see what a JSON Web Token looks like,
247

247

00:08:55,620  -->  00:08:57,270
it looks something like this.
248

248

00:08:57,270  -->  00:08:59,100
Notice, you've got some curly brackets
249

249

00:08:59,100  -->  00:09:01,530
and we have these different key pairs together.
250

250

00:09:01,530  -->  00:09:04,590
alg, h256, what do you think that means?
251

251

00:09:04,590  -->  00:09:05,580
That's an algorithm.
252

252

00:09:05,580  -->  00:09:07,020
What algorithm we're going to use
253

253

00:09:07,020  -->  00:09:09,420
to hash this and make sure it has integrity?
254

254

00:09:09,420  -->  00:09:13,380
In this case, h256, which means SHA-256.
255

255

00:09:13,380  -->  00:09:14,213
It says what type it is?
256

256

00:09:14,213  -->  00:09:17,520
In this case, a JWT, a JSON Web Token.
257

257

00:09:17,520  -->  00:09:18,770
Then you see the next set,
258

258

00:09:18,770  -->  00:09:20,340
we have sub, which is the subject.
259

259

00:09:20,340  -->  00:09:21,240
Who are we talking about?
260

260

00:09:21,240  -->  00:09:22,800
What's the ID of that person?
261

261

00:09:22,800  -->  00:09:24,840
Then we have the name, in this case, Jason.
262

262

00:09:24,840  -->  00:09:27,870
We have the email, in this case, support@diontraining.com.
263

263

00:09:27,870  -->  00:09:29,100
Now, these are just two fields
264

264

00:09:29,100  -->  00:09:31,350
that are attributes of that subject
265

265

00:09:31,350  -->  00:09:32,970
whoever that ID string is,
266

266

00:09:32,970  -->  00:09:35,910
and in this case it's Jason with support@diontraining.com.
267

267

00:09:35,910  -->  00:09:38,040
We can have lots of different fields in this,
268

268

00:09:38,040  -->  00:09:39,810
but in this case I wanted to keep it simple
269

269

00:09:39,810  -->  00:09:41,190
and just show you the basics
270

270

00:09:41,190  -->  00:09:43,920
and this would be a very, very simple JWT.
271

271

00:09:43,920  -->  00:09:46,710
Now, if you want to send this JWT over to a web server,
272

272

00:09:46,710  -->  00:09:47,970
how can you send it?
273

273

00:09:47,970  -->  00:09:50,370
Well, just like we were using with SOAP and SAML,
274

274

00:09:50,370  -->  00:09:52,470
where we can put it in as part of the url,
275

275

00:09:52,470  -->  00:09:54,300
we can do the exact same thing.
276

276

00:09:54,300  -->  00:09:58,500
Here you'll see diontraining.com/authorize, question mark,
277

277

00:09:58,500  -->  00:09:59,910
and then all that stuff in white,
278

278

00:09:59,910  -->  00:10:02,490
which is essentially base 64 encoding.
279

279

00:10:02,490  -->  00:10:05,400
We take that JWT, we encode it using base 64
280

280

00:10:05,400  -->  00:10:07,380
and we pass it as part of the url.
281

281

00:10:07,380  -->  00:10:09,330
That's a great way to get information from one place
282

282

00:10:09,330  -->  00:10:11,733
to another using JSON Web Tokens.
