-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add http basic auth for receive
Signed-off-by: Sergey Lanzman <[email protected]>
- Loading branch information
1 parent
4a84785
commit e574c6a
Showing
4 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package middleware | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
// BasicAuth returns a middleware that checks HTTP Basic Authentication. | ||
// If the username or password do not match the expected credentials, | ||
// a 401 Unauthorized response is returned. Otherwise, the wrapped handler | ||
// is invoked. | ||
func BasicAuth(next http.HandlerFunc, expectedUser, expectedPassword string) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
user, pass, ok := r.BasicAuth() | ||
if !ok || user != expectedUser || pass != expectedPassword { | ||
http.Error(w, "Unauthorized", http.StatusUnauthorized) | ||
return | ||
} | ||
next(w, r) | ||
} | ||
} |