-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): skip auth on specific endpoints
Signed-off-by: Jakub Dyszkiewicz <[email protected]>
- Loading branch information
1 parent
716aaf2
commit c17faff
Showing
4 changed files
with
88 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package authn | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/emicklei/go-restful/v3" | ||
) | ||
|
||
const ( | ||
MetadataAuthKey = "auth" | ||
MetadataAuthSkip = "skip" | ||
) | ||
|
||
// UnauthorizedPathPrefixes is another way to add path prefixes as unauthorized endpoint. | ||
// Prefer MetadataAuthKey, use UnauthorizedPathPrefixes if needed. | ||
var UnauthorizedPathPrefixes = map[string]struct{}{ | ||
"/gui": {}, | ||
} | ||
|
||
func SkipAuth(request *restful.Request) bool { | ||
if route := request.SelectedRoute(); route != nil { | ||
if route.Metadata()[MetadataAuthKey] == MetadataAuthSkip { | ||
return true | ||
} | ||
} | ||
for prefix := range UnauthorizedPathPrefixes { | ||
if strings.HasPrefix(request.Request.RequestURI, prefix) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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