Documentation
¶
Index ¶
- func GetGrantTypeByReponseType(responseType string) []string
- func ValidateGrantType(client model.IClient, grantType string) bool
- func ValidateReturnUri(client model.IClient, uri string) bool
- func ValidateScope(client model.IClient, scopes []string) bool
- type AuthorizeService
- type ClientService
- type ConsentService
- type DefaultAuthorizeService
- func (src *DefaultAuthorizeService) CreateAuthorization(request *request.AuthorizeRequest, principal string) *model.Authorization
- func (srv *DefaultAuthorizeService) CreateDeviceAuthorization(clientId string, scope string, issuer string) *model.Authorization
- func (srv *DefaultAuthorizeService) GenerateDeviceCode() string
- func (srv *DefaultAuthorizeService) GenerateUserCode() string
- func (srv *DefaultAuthorizeService) GetAuthorizationByAccessToken(token string) *model.Authorization
- func (srv *DefaultAuthorizeService) GetAuthorizationByCode(code string) *model.Authorization
- func (srv *DefaultAuthorizeService) GetAuthorizationByDeviceCode(device_code string) *model.Authorization
- func (srv *DefaultAuthorizeService) GetAuthorizationByRefreshToken(token string) *model.Authorization
- func (srv *DefaultAuthorizeService) GetAuthorizationByUserCode(user_code string) *model.Authorization
- func (srv *DefaultAuthorizeService) GetAuthorizeionByPassword(request *request.PasswordRequest) (*model.Authorization, error)
- func (srv *DefaultAuthorizeService) NewId() string
- func (srv *DefaultAuthorizeService) Remove(auth *model.Authorization)
- func (srv *DefaultAuthorizeService) Save(auth *model.Authorization)
- type DefaultClientService
- func (cs *DefaultClientService) GetClient(clientId string) (model.IClient, error)
- func (cs *DefaultClientService) SetClientRepository(repo repo.ClientRepository)
- func (cs *DefaultClientService) ValidateClient(client model.IClient) error
- func (cs *DefaultClientService) ValidateLogoutUri(clientId string, url string) error
- func (cs *DefaultClientService) ValidateSecret(clientId string, secret string) bool
- type DefaultConsentService
- func (cc *DefaultConsentService) GetConsents(clientId string, principal string) ([]string, error)
- func (cc *DefaultConsentService) RemoveConsents(clientId string, principal string) error
- func (cc *DefaultConsentService) RequireConsent(clientId string, principal string, scopes []string) bool
- func (cc *DefaultConsentService) SaveConsents(clientId string, principal string, scopes []string) error
- type DefaultUserService
- type SampleTokenService
- type TokenService
- type UserService
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateReturnUri ¶ added in v0.12.1
Types ¶
type AuthorizeService ¶
type AuthorizeService interface {
// NewId generates a unique identifier for a new authorization.
NewId() string
// Save persists an authorization object.
Save(*model.Authorization)
// Remove deletes an authorization object.
Remove(*model.Authorization)
// GetAuthorizationByCode retrieves an authorization object by its code.
GetAuthorizationByCode(string) *model.Authorization
// GetAuthorizationByAccessToken retrieves an authorization object by its access token.
GetAuthorizationByAccessToken(string) *model.Authorization
// GetAuthorizationByRefreshToken retrieves an authorization object by its refresh token.
GetAuthorizationByRefreshToken(string) *model.Authorization
// GetAuthorizeionByPassword retrieves an authorization object by password verification, may return an error.
GetAuthorizeionByPassword(*request.PasswordRequest) (*model.Authorization, error)
// GetAuthorizationByDeviceCode retrieves an authorization object by device code.
GetAuthorizationByDeviceCode(device_code string) *model.Authorization
// GetAuthorizationByUserCode retrieves an authorization object by user code.
GetAuthorizationByUserCode(user_code string) *model.Authorization
// CreateDeviceAuthorization creates a device code authorization.
CreateDeviceAuthorization(clientId string, scope string, issuer string) *model.Authorization
// CreateAuthorization creates a new authorization based on the provided authorization code request information.
CreateAuthorization(request *request.AuthorizeRequest, principal string) *model.Authorization
// GenerateUserCode generates a unique user code for device code authorization.
GenerateUserCode() string
// GenerateDeviceCode generates a unique device code for device code authorization.
GenerateDeviceCode() string
}
AuthorizeService defines the interface for authorization operations.
type ClientService ¶
type ClientService interface {
// GetClient retrieves a client object by the client ID.
// Parameters:
// clientId - The unique identifier of the client.
// Returns:
// model.IClient - An object that implements the client interface.
// error - An error message if an error occurs.
GetClient(clientId string) (model.IClient, error)
// ValidateSecret verifies whether the client's secret is valid.
// Parameters:
// clientId - The unique identifier of the client.
// secret - The client's secret.
// Returns:
// bool - True if the secret is valid, otherwise false.
ValidateSecret(clientId string, secret string) bool
// ValidateClient checks if a client object is valid.
// Parameters:
// client - The client object to validate.
// Returns:
// error - An error message if the client object is invalid.
ValidateClient(client model.IClient) error
// SetClientRepository sets the client repository.
// Parameters:
// clientRepository - The client repository interface.
// This method is used for dependency injection to access the client data store when needed.
SetClientRepository(clientRepository repo.ClientRepository)
// ValidateLogoutUri validates the logout URI.
//
// clientId is the client identifier used to ensure the URI belongs to the correct client.
// url is the logout URI to validate.
//
// The function returns an error if the URI is invalid or unsafe.
ValidateLogoutUri(clientId string, url string) error
}
type ConsentService ¶
type ConsentService interface {
// GetConsents retrieves all consents for a given client and principal.
// Parameters:
// clientId - the unique identifier of the client application.
// principal - the identifier of the consent principal, usually the user ID.
// Returns:
// A list of consents (scopes) agreed to by the principal for the client application.
// An error, if any occurs during the retrieval process.
GetConsents(clientId string, principal string) ([]string, error)
// SaveConsents saves new consents for a given client and principal.
// Parameters:
// clientId - the unique identifier of the client application.
// principal - the identifier of the consent principal, usually the user ID.
// scopes - a list of scopes (consent items) to be saved.
// Returns:
// An error, if any occurs during the saving process.
SaveConsents(clientId string, principal string, scopes []string) error
// RemoveConsents removes all consents for a given client and principal.
// Parameters:
// clientId - the unique identifier of the client application.
// principal - the identifier of the consent principal, usually the user ID.
// Returns:
// An error, if any occurs during the removal process.
RemoveConsents(clientId string, principal string) error
// RequireConsent checks if a given client and principal require consent for specific scopes.
// Parameters:
// clientId - the unique identifier of the client application.
// principal - the identifier of the consent principal, usually the user ID.
// scopes - a list of scopes (consent items) to be checked.
// Returns:
// true if the principal needs to provide consent for the specified scopes under the client application; otherwise, false.
RequireConsent(clientId string, principal string, scopes []string) bool
}
ConsentService defines the interface for handling user consents. It provides operations for querying, saving, removing, and checking consents.
type DefaultAuthorizeService ¶
type DefaultAuthorizeService struct {
TokenService TokenService
UserService UserService
ClientService ClientService
Config *conf.Config
// contains filtered or unexported fields
}
func NewAuthorizeService ¶
func NewAuthorizeService(ts TokenService, config *conf.Config, repo repo.AuthorizationRepository, userService UserService) *DefaultAuthorizeService
func (*DefaultAuthorizeService) CreateAuthorization ¶
func (src *DefaultAuthorizeService) CreateAuthorization(request *request.AuthorizeRequest, principal string) *model.Authorization
func (*DefaultAuthorizeService) CreateDeviceAuthorization ¶
func (srv *DefaultAuthorizeService) CreateDeviceAuthorization(clientId string, scope string, issuer string) *model.Authorization
func (*DefaultAuthorizeService) GenerateDeviceCode ¶
func (srv *DefaultAuthorizeService) GenerateDeviceCode() string
func (*DefaultAuthorizeService) GenerateUserCode ¶
func (srv *DefaultAuthorizeService) GenerateUserCode() string
func (*DefaultAuthorizeService) GetAuthorizationByAccessToken ¶
func (srv *DefaultAuthorizeService) GetAuthorizationByAccessToken(token string) *model.Authorization
func (*DefaultAuthorizeService) GetAuthorizationByCode ¶
func (srv *DefaultAuthorizeService) GetAuthorizationByCode(code string) *model.Authorization
func (*DefaultAuthorizeService) GetAuthorizationByDeviceCode ¶
func (srv *DefaultAuthorizeService) GetAuthorizationByDeviceCode(device_code string) *model.Authorization
func (*DefaultAuthorizeService) GetAuthorizationByRefreshToken ¶
func (srv *DefaultAuthorizeService) GetAuthorizationByRefreshToken(token string) *model.Authorization
func (*DefaultAuthorizeService) GetAuthorizationByUserCode ¶
func (srv *DefaultAuthorizeService) GetAuthorizationByUserCode(user_code string) *model.Authorization
func (*DefaultAuthorizeService) GetAuthorizeionByPassword ¶
func (srv *DefaultAuthorizeService) GetAuthorizeionByPassword(request *request.PasswordRequest) (*model.Authorization, error)
func (*DefaultAuthorizeService) NewId ¶
func (srv *DefaultAuthorizeService) NewId() string
func (*DefaultAuthorizeService) Remove ¶
func (srv *DefaultAuthorizeService) Remove(auth *model.Authorization)
func (*DefaultAuthorizeService) Save ¶
func (srv *DefaultAuthorizeService) Save(auth *model.Authorization)
type DefaultClientService ¶
type DefaultClientService struct {
ClientRepository repo.ClientRepository
}
func NewClientService ¶
func NewClientService(clientRepository repo.ClientRepository) *DefaultClientService
func (*DefaultClientService) GetClient ¶
func (cs *DefaultClientService) GetClient(clientId string) (model.IClient, error)
func (*DefaultClientService) SetClientRepository ¶
func (cs *DefaultClientService) SetClientRepository(repo repo.ClientRepository)
func (*DefaultClientService) ValidateClient ¶
func (cs *DefaultClientService) ValidateClient(client model.IClient) error
func (*DefaultClientService) ValidateLogoutUri ¶ added in v0.12.0
func (cs *DefaultClientService) ValidateLogoutUri(clientId string, url string) error
func (*DefaultClientService) ValidateSecret ¶
func (cs *DefaultClientService) ValidateSecret(clientId string, secret string) bool
type DefaultConsentService ¶
type DefaultConsentService struct {
Repo repo.ConsentRepository
}
func (*DefaultConsentService) GetConsents ¶
func (cc *DefaultConsentService) GetConsents(clientId string, principal string) ([]string, error)
func (*DefaultConsentService) RemoveConsents ¶
func (cc *DefaultConsentService) RemoveConsents(clientId string, principal string) error
func (*DefaultConsentService) RequireConsent ¶
func (cc *DefaultConsentService) RequireConsent(clientId string, principal string, scopes []string) bool
need to popup the consent page or not
func (*DefaultConsentService) SaveConsents ¶
func (cc *DefaultConsentService) SaveConsents(clientId string, principal string, scopes []string) error
type DefaultUserService ¶
type DefaultUserService struct {
UserRepository repo.UserRepository
}
func (*DefaultUserService) GetUser ¶
func (us *DefaultUserService) GetUser(userId string) (model.IUser, error)
func (*DefaultUserService) GetUserByName ¶
func (us *DefaultUserService) GetUserByName(userName string) (model.IUser, error)
func (*DefaultUserService) VerifyPassword ¶
func (us *DefaultUserService) VerifyPassword(userName string, password string) bool
type SampleTokenService ¶
type SampleTokenService struct {
}
func (*SampleTokenService) GenerateIDToken ¶
func (s *SampleTokenService) GenerateIDToken(authorization *model.Authorization) (string, error)
func (*SampleTokenService) GenerateRefreshToken ¶
func (s *SampleTokenService) GenerateRefreshToken(authorization *model.Authorization) (string, error)
func (*SampleTokenService) GenerateToken ¶
func (s *SampleTokenService) GenerateToken(authorization *model.Authorization) (string, error)
type TokenService ¶
type TokenService interface {
// GenerateToken generates an access token based on the authorization information.
// Parameters:
// - authorization: An object containing user authorization details.
// Returns:
// - string: The generated access token.
// - error: If there is an error during token generation, returns the error.
GenerateToken(authorization *model.Authorization) (string, error)
// GenerateRefreshToken generates a refresh token based on the authorization information.
// Parameters:
// - authorization: An object containing user authorization details.
// Returns:
// - string: The generated refresh token.
// - error: If there is an error during token generation, returns the error.
GenerateRefreshToken(authorization *model.Authorization) (string, error)
// GenerateIDToken generates an identity token based on the authorization information.
// Parameters:
// - authorization: An object containing user authorization details.
// Returns:
// - string: The generated identity token.
// - error: If there is an error during token generation, returns the error.
GenerateIDToken(authorization *model.Authorization) (string, error)
}
TokenService defines the service interface for token generation. This interface includes three methods for generating different types of tokens.
type UserService ¶
type UserService interface {
// GetUser retrieves user information by user ID.
// Parameters:
// userId: The user's ID.
// Returns:
// IUser: User information interface.
// error: An error if the operation fails.
GetUser(userId string) (model.IUser, error)
// GetUserByName retrieves user information by username.
// Parameters:
// userName: The username.
// Returns:
// IUser: User information interface.
// error: An error if the operation fails.
GetUserByName(userName string) (model.IUser, error)
// VerifyPassword checks whether the provided username and password match.
// Parameters:
// userName: The username.
// password: The password.
// Returns:
// bool: True if the password matches, false otherwise.
VerifyPassword(userName string, password string) bool
}
UserService defines the interface for user service, including user retrieval and password verification functionalities.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.