Skip to content

Commit

Permalink
Fixing minor redirect bug on ExchangeCode
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Dias committed Aug 20, 2020
1 parent 911ae54 commit 594cf71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions api/authentication_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func authenticationValidHandler(
authResult, err := sasUC.WithContext(r.Context()).
AuthenticateAccessToken(qs["accessToken"][0])
referer := qs["referer"][0]

if err != nil {
l.WithError(err).Error("authenticationValidHandler AuthenticateAccessToken failed")
v := url.Values{}
Expand All @@ -120,6 +121,7 @@ func authenticationValidHandler(
if strings.Contains(referer, "?") {
sep = "&"
}

http.Redirect(
w, r, fmt.Sprintf("%s%s%s", referer, sep, v.Encode()),
http.StatusSeeOther,
Expand Down
16 changes: 8 additions & 8 deletions oauth2/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"github.com/topfreegames/Will.IAM/models"
)

// DevOAuth2Provider is a Provider used in development environment
// DevOAuth2Provider is a Provider used in development environment
type DevOAuth2Provider struct {
config DevOAuth2ProviderConfig
}

// DevOAuth2ProviderConfig are the basic required informations to use
// DevOAuth2ProviderConfig are the basic required informations to use
// our OAuth2 dev server as oauth2 provider
type DevOAuth2ProviderConfig struct {
RedirectURL string
Expand All @@ -21,23 +21,23 @@ type DevOAuth2ProviderConfig struct {

// NewDevOAuth2Provider ctor
func NewDevOAuth2Provider(config DevOAuth2ProviderConfig) *DevOAuth2Provider {
return &DevOAuth2Provider{ config: config }
return &DevOAuth2Provider{config: config}
}

// BuildAuthURL creates the url used to authorize an user against OAuth2 dev server
func (p *DevOAuth2Provider) BuildAuthURL(any string) string {
return fmt.Sprintf("%s?response_type=code&redirect_uri=%s", p.config.AuthorizationURL, p.config.RedirectURL)
func (p *DevOAuth2Provider) BuildAuthURL(state string) string {
return fmt.Sprintf("%s?response_type=code&redirect_uri=%s&state=%s", p.config.AuthorizationURL, p.config.RedirectURL, state)
}

// ExchangeCode dummy
func (p *DevOAuth2Provider) ExchangeCode(any string) (*models.AuthResult, error) {
// ExchangeCode validates an auth code against a OAuth2 server
func (p *DevOAuth2Provider) ExchangeCode(code string) (*models.AuthResult, error) {
return &models.AuthResult{
AccessToken: "any",
Email: "any",
}, nil
}

// Authenticate dummy
// Authenticate verifies if an accessToken is valid and maybe refresh it
func (p *DevOAuth2Provider) Authenticate(accessToken string) (*models.AuthResult, error) {
return &models.AuthResult{
AccessToken: accessToken,
Expand Down

0 comments on commit 594cf71

Please sign in to comment.