课程: Secure Coding in Go

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Limit access

Solution: Limit access

(upbeat music) - [Instructor] Here is my solution, for the RequireAdmin. We create a new function, and then gets the Request User. And if it's not okay, meaning we don't have a user. Otherwise, we check that the user has the role of admin, and again, if they don't, we issue unauthorized, otherwise, we serve the HTTP. Let's have a look. So, we are going to run it, start without Debugging, and we are going to look at the Debug console. So, let's start with curl dash I http, local host, 8080, admin. No user, no credentials. We get unauthorized. Now, let's try to do it with Jane's credentials. So, I'm going to pass Heather, authorization and then we're going to say, Bearer and with Jane's password. And here, we are denied again. And now, we're going to use the token that Moss has. So, m4ur1c3, and now, we're in.

内容