account registration flow working
This commit is contained in:
@ -20,6 +20,7 @@ package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -169,19 +170,40 @@ func (s *s) ValidationBearerToken(r *http.Request) (oauth2.TokenInfo, error) {
|
||||
//
|
||||
// The ti parameter refers to an existing Application token that was used to make the upstream
|
||||
// request. This token needs to be validated and exist in database in order to create a new token.
|
||||
func (s *s) GenerateUserAccessToken(ti oauth2.TokenInfo, clientSecret string, userID string) (accessToken oauth2.TokenInfo, err error) {
|
||||
tgr := &oauth2.TokenGenerateRequest{
|
||||
func (s *s) GenerateUserAccessToken(ti oauth2.TokenInfo, clientSecret string, userID string) (oauth2.TokenInfo, error) {
|
||||
|
||||
authToken, err := s.server.Manager.GenerateAuthToken(context.Background(), oauth2.Code, &oauth2.TokenGenerateRequest{
|
||||
ClientID: ti.GetClientID(),
|
||||
ClientSecret: clientSecret,
|
||||
UserID: userID,
|
||||
RedirectURI: ti.GetRedirectURI(),
|
||||
Scope: ti.GetScope(),
|
||||
Code: ti.GetCode(),
|
||||
// CodeChallenge: ti.GetCodeChallenge(),
|
||||
// CodeChallengeMethod: ti.GetCodeChallengeMethod(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating first auth token: %s", err)
|
||||
}
|
||||
if authToken == nil {
|
||||
return nil, errors.New("generated auth token was empty")
|
||||
}
|
||||
s.log.Tracef("obtained auth token: %+v", authToken)
|
||||
|
||||
return s.server.Manager.GenerateAccessToken(context.Background(), oauth2.AuthorizationCode, tgr)
|
||||
accessToken, err := s.server.Manager.GenerateAccessToken(context.Background(), oauth2.AuthorizationCode, &oauth2.TokenGenerateRequest{
|
||||
ClientID: authToken.GetClientID(),
|
||||
ClientSecret: clientSecret,
|
||||
// UserID: userID,
|
||||
RedirectURI: authToken.GetRedirectURI(),
|
||||
Scope: authToken.GetScope(),
|
||||
Code: authToken.GetCode(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error generating first auth token: %s", err)
|
||||
}
|
||||
if accessToken == nil {
|
||||
return nil, errors.New("generated access token was empty")
|
||||
}
|
||||
s.log.Tracef("obtained access token: %+v", accessToken)
|
||||
return accessToken, nil
|
||||
}
|
||||
|
||||
func New(database db.DB, log *logrus.Logger) Server {
|
||||
@ -228,5 +250,6 @@ func New(database db.DB, log *logrus.Logger) Server {
|
||||
srv.SetClientInfoHandler(server.ClientFormHandler)
|
||||
return &s{
|
||||
server: srv,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
@ -121,6 +121,9 @@ func (pts *tokenStore) RemoveByRefresh(ctx context.Context, refresh string) erro
|
||||
|
||||
// GetByCode selects a token from the DB based on the Code field
|
||||
func (pts *tokenStore) GetByCode(ctx context.Context, code string) (oauth2.TokenInfo, error) {
|
||||
if code == "" {
|
||||
return nil, nil
|
||||
}
|
||||
pgt := &Token{
|
||||
Code: code,
|
||||
}
|
||||
@ -132,6 +135,9 @@ func (pts *tokenStore) GetByCode(ctx context.Context, code string) (oauth2.Token
|
||||
|
||||
// GetByAccess selects a token from the DB based on the Access field
|
||||
func (pts *tokenStore) GetByAccess(ctx context.Context, access string) (oauth2.TokenInfo, error) {
|
||||
if access == "" {
|
||||
return nil, nil
|
||||
}
|
||||
pgt := &Token{
|
||||
Access: access,
|
||||
}
|
||||
@ -143,6 +149,9 @@ func (pts *tokenStore) GetByAccess(ctx context.Context, access string) (oauth2.T
|
||||
|
||||
// GetByRefresh selects a token from the DB based on the Refresh field
|
||||
func (pts *tokenStore) GetByRefresh(ctx context.Context, refresh string) (oauth2.TokenInfo, error) {
|
||||
if refresh == "" {
|
||||
return nil, nil
|
||||
}
|
||||
pgt := &Token{
|
||||
Refresh: refresh,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user