-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: create interfaces for AuthN and AuthZ (#1286)
This change defines interfaces for AuthN and AuthZ, which helps modularize the auth components in a way that each package takes care of its own business and has minimal knowledge of the implementation details of dependencies. The goal is to hide complexity and reduce engineer cognitive load. Signed-off-by: Keran Yang <yangkr920208@gmail.com>
- Loading branch information
Showing
10 changed files
with
110 additions
and
116 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,10 @@ | ||
package authn | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
type Authenticator interface { | ||
// Authenticate is used to validate the user's identity. | ||
// If the user is authenticated, the function returns user information. | ||
// Otherwise, empty information with the corresponding error. | ||
Authenticate(c *gin.Context) (*UserInfo, error) | ||
} |
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,12 @@ | ||
package authz | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
type Authorizer interface { | ||
// Authorize checks if a user is authorized to access the resource. | ||
// c is the gin context. | ||
// g is the list of groups the user belongs to. | ||
// Authorize trusts that the user is already authenticated and directly uses the groups to authorize the user. | ||
// please don't use gin to get the user information again. | ||
Authorize(c *gin.Context, g []string) (bool, error) | ||
} |
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 was deleted.
Oops, something went wrong.