github.com/wanliu/go-oauth2-server@v0.0.0-20180817021415-f928fa1580df/oauth/service_interface.go (about)

     1  package oauth
     2  
     3  import (
     4  	"github.com/gorilla/mux"
     5  	"github.com/jinzhu/gorm"
     6  	"github.com/wanliu/go-oauth2-server/config"
     7  	"github.com/wanliu/go-oauth2-server/models"
     8  	"github.com/wanliu/go-oauth2-server/session"
     9  	"github.com/wanliu/go-oauth2-server/util/routes"
    10  )
    11  
    12  // ServiceInterface defines exported methods
    13  type ServiceInterface interface {
    14  	// Exported methods
    15  	GetConfig() *config.Config
    16  	RestrictToRoles(allowedRoles ...string)
    17  	IsRoleAllowed(role string) bool
    18  	FindRoleByID(id string) (*models.OauthRole, error)
    19  	CreateRole(id, name string) (*models.OauthRole, error)
    20  	GetRoutes() []routes.Route
    21  	RegisterRoutes(router *mux.Router, prefix string)
    22  	ClientExists(clientID string) bool
    23  	FindClientByClientID(clientID string) (*models.OauthClient, error)
    24  	ListClientByUserID(userId string, offset, count int) ([]models.OauthClient, error)
    25  	GetUserByToken(string) (*models.OauthUser, error)
    26  	CreateClient(clientID, secret, redirectURI string) (*models.OauthClient, error)
    27  	CreateClientByUserID(userId, name, clientID, secret, redirectURI string) (*models.OauthClient, error)
    28  	CreateClientTx(tx *gorm.DB, clientID, secret, redirectURI string) (*models.OauthClient, error)
    29  	AuthClient(clientID, secret string) (*models.OauthClient, error)
    30  	UserExists(username string) bool
    31  	FindUserByUsername(username string) (*models.OauthUser, error)
    32  	FindUserByID(username string) (*models.OauthUser, error)
    33  	CreateUser(roleID, username, password string) (*models.OauthUser, error)
    34  	CreateUserTx(tx *gorm.DB, roleID, username, password string) (*models.OauthUser, error)
    35  	SetPassword(user *models.OauthUser, password string) error
    36  	SetPasswordTx(tx *gorm.DB, user *models.OauthUser, password string) error
    37  	UpdateUsername(user *models.OauthUser, username string) error
    38  	UpdateUser(user *models.OauthUser, params Params) error
    39  	UpdateUsernameTx(db *gorm.DB, user *models.OauthUser, username string) error
    40  	AuthUser(username, thePassword string) (*models.OauthUser, error)
    41  	GetScope(requestedScope string) (string, error)
    42  	GetDefaultScope() string
    43  	ScopeExists(requestedScope string) bool
    44  	CreateScope(scope string, isdefault bool) (*models.OauthScope, error)
    45  	Login(client *models.OauthClient, user *models.OauthUser, scope string) (*models.OauthAccessToken, *models.OauthRefreshToken, error)
    46  	GrantAuthorizationCode(client *models.OauthClient, user *models.OauthUser, expiresIn int, redirectURI, scope string) (*models.OauthAuthorizationCode, error)
    47  	GrantAccessToken(client *models.OauthClient, user *models.OauthUser, expiresIn int, scope string) (*models.OauthAccessToken, error)
    48  	GetOrCreateRefreshToken(client *models.OauthClient, user *models.OauthUser, expiresIn int, scope string) (*models.OauthRefreshToken, error)
    49  	GetValidRefreshToken(token string, client *models.OauthClient) (*models.OauthRefreshToken, error)
    50  	Authenticate(token string) (*models.OauthAccessToken, error)
    51  	NewIntrospectResponseFromAccessToken(accessToken *models.OauthAccessToken) (*IntrospectResponse, error)
    52  	NewIntrospectResponseFromRefreshToken(refreshToken *models.OauthRefreshToken) (*IntrospectResponse, error)
    53  	ClearUserTokens(userSession *session.UserSession)
    54  	Close()
    55  }