1
00:00:01,758 --> 00:00:03,341
Hey guys and welcome back.

2
00:00:03,341 --> 00:00:04,709
In this video we are going to look

3
00:00:04,709 --> 00:00:07,756
at how to require a fresh token

4
00:00:07,756 --> 00:00:09,621
and I think you can probably guess

5
00:00:09,621 --> 00:00:11,613
how to do it just based on

6
00:00:11,613 --> 00:00:14,557
what decorator we've used so far,

7
00:00:14,557 --> 00:00:16,213
but this is gonna be a short video

8
00:00:16,213 --> 00:00:18,525
and we're just gonna open up the item resource

9
00:00:18,525 --> 00:00:21,628
and we are going to add to the post method,

10
00:00:21,628 --> 00:00:23,107
now a new decorator,

11
00:00:23,107 --> 00:00:26,595
to say that is requires a fresh jwt.

12
00:00:26,595 --> 00:00:30,012
Now, the decorator that says jwt required

13
00:00:31,220 --> 00:00:34,373
means that this method here will only run

14
00:00:34,373 --> 00:00:37,395
if we have an access token provided.

15
00:00:37,395 --> 00:00:39,419
A valid access token provided.

16
00:00:39,419 --> 00:00:42,619
So, that can be a fresh token or a non-fresh token,

17
00:00:42,619 --> 00:00:45,357
either of those will work.

18
00:00:45,357 --> 00:00:49,690
For the post, we're gonna do at @fresh_jwt_required.

19
00:00:51,626 --> 00:00:53,043
It's that simple.

20
00:00:53,880 --> 00:00:57,617
Needs a fresh jwt if the access token that comes through

21
00:00:57,617 --> 00:01:00,367
to this post method is not fresh,

22
00:01:01,336 --> 00:01:04,881
it's gonna say, no you need a fresh access token.

23
00:01:04,881 --> 00:01:06,551
You've authenticated correctly,

24
00:01:06,551 --> 00:01:09,023
but you need a fresh token,

25
00:01:09,023 --> 00:01:10,951
not a non-fresh one.

26
00:01:10,951 --> 00:01:13,871
Of course, you have to go ahead and import this

27
00:01:13,871 --> 00:01:14,704
and so once again,

28
00:01:14,704 --> 00:01:17,903
we're gonna split this into multiple lines.

29
00:01:17,903 --> 00:01:20,903
Just to make this a little bit nicer

30
00:01:22,591 --> 00:01:24,138
and like that.

31
00:01:24,138 --> 00:01:27,292
That's it, us imported fresh jwt required

32
00:01:27,292 --> 00:01:29,187
and we can use it in here.

33
00:01:29,187 --> 00:01:31,537
You can use it in any end port you want of course,

34
00:01:31,537 --> 00:01:32,729
this is just an example,

35
00:01:32,729 --> 00:01:35,017
but now you won't be able to create new items

36
00:01:35,017 --> 00:01:38,145
unless you've just logged in.

37
00:01:38,145 --> 00:01:39,200
So, that's it.

38
00:01:39,200 --> 00:01:41,755
Of course in here you can still use a claims and all that.

39
00:01:41,755 --> 00:01:44,723
That's completely unaffected by whether a fresh jwt

40
00:01:44,723 --> 00:01:47,109
is required or not.

41
00:01:47,109 --> 00:01:48,739
This just means that the flag

42
00:01:48,739 --> 00:01:51,459
in the jwt has to be fresh is true,

43
00:01:51,459 --> 00:01:55,124
and that subsequently means normally,

44
00:01:55,124 --> 00:01:59,547
that this jwt was just created by logging in.

45
00:01:59,547 --> 00:02:00,554
Of course as an aside,

46
00:02:00,554 --> 00:02:02,996
just to make things clear,

47
00:02:02,996 --> 00:02:05,906
here in the user Drop-UI the token refresh resource,

48
00:02:05,906 --> 00:02:07,596
we've created a new access token

49
00:02:07,596 --> 00:02:09,466
and set fresh to false,

50
00:02:09,466 --> 00:02:11,236
but if we set fresh to true,

51
00:02:11,236 --> 00:02:14,402
that means that all tokens this user would create,

52
00:02:14,402 --> 00:02:19,074
both by logging in and by refreshing would be fresh.

53
00:02:19,074 --> 00:02:23,242
So it's up to us to determine what fresh means,

54
00:02:23,242 --> 00:02:25,170
but normally it's used in this way.

55
00:02:25,170 --> 00:02:27,738
When you've just logged in that's a fresh token.

56
00:02:27,738 --> 00:02:28,770
When you're refreshing,

57
00:02:28,770 --> 00:02:30,555
that's not a fresh token.

58
00:02:30,555 --> 00:02:32,002
Hopefully that makes sense.

59
00:02:32,002 --> 00:02:34,458
Just wanted to show you how to require a fresh token

60
00:02:34,458 --> 00:02:36,039
just in case you have an end point

61
00:02:36,039 --> 00:02:39,928
that you wanna really make sure that's the right user.

62
00:02:39,928 --> 00:02:41,113
That's it for this video

63
00:02:41,113 --> 00:02:43,465
and I'll see you on the next one.

