-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Upgrade sqlboiler * Keep uploads data in the database * Improve tus handler declaration * Add preliminary e2e tests for publish * Add user metadata to sentry context * Add stream creation code * Manual master merge * Tidy up go.mod * Implement publish v3 * Initialize reflector uploader per each upload * Fix reflector config indentation * Improve geopublish error output * Improve forklift logging * Fix livestream url signing * Complete e2e publish v3 test * Improve media metadata detection * Fix docker lbrynet port in wait script * Clean up failing tests * Fix test wallet loading routine * Add ffmpeg and extra variables go github actions * Unload testing wallet before loading it * Improve test wallet cleanup * Fix carriage tests * Add geopublish metrics * Remove models tests * Improve test wallet handling * Alleviate test wallet race condition
- Loading branch information
Showing
85 changed files
with
7,932 additions
and
4,253 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
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
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,65 @@ | ||
package auth | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/OdyseeTeam/odysee-api/app/wallet" | ||
"github.com/OdyseeTeam/odysee-api/internal/errors" | ||
"github.com/OdyseeTeam/odysee-api/internal/ip" | ||
"github.com/OdyseeTeam/odysee-api/models" | ||
"github.com/lbryio/transcoder/pkg/logging" | ||
) | ||
|
||
type universalUserGetter struct { | ||
logger logging.KVLogger | ||
auther Authenticator | ||
provider Provider | ||
} | ||
|
||
func NewUniversalUserGetter(auther Authenticator, provider Provider, logger logging.KVLogger) *universalUserGetter { | ||
return &universalUserGetter{ | ||
auther: auther, | ||
provider: provider, | ||
logger: logger, | ||
} | ||
} | ||
|
||
func (g *universalUserGetter) GetFromRequest(r *http.Request) (*models.User, error) { | ||
log := g.logger | ||
token, err := g.auther.GetTokenFromRequest(r) | ||
// No oauth token present in request, try legacy method | ||
if errors.Is(err, wallet.ErrNoAuthInfo) { | ||
// TODO: Remove this pathway after legacy tokens go away. | ||
if token, ok := r.Header[wallet.LegacyTokenHeader]; ok { | ||
addr := ip.ForRequest(r) | ||
user, err := g.provider(token[0], addr) | ||
if err != nil { | ||
log.Info("user authentication failed", "err", err, "method", "token") | ||
return nil, err | ||
} | ||
if user == nil { | ||
err := wallet.ErrNoAuthInfo | ||
log.Info("unauthorized user", "err", err, "method", "token") | ||
return nil, err | ||
} | ||
log.Debug("user authenticated", "user", user.ID, "method", "token") | ||
return user, nil | ||
} | ||
return nil, errors.Err(wallet.ErrNoAuthInfo) | ||
} else if err != nil { | ||
return nil, err | ||
} | ||
|
||
user, err := g.auther.Authenticate(token, ip.ForRequest(r)) | ||
if err != nil { | ||
log.Info("user authentication failed", "err", err, "method", "oauth") | ||
return nil, err | ||
} | ||
if user == nil { | ||
err := wallet.ErrNoAuthInfo | ||
log.Info("unauthorized user", "err", err, "method", "oauth") | ||
return nil, err | ||
} | ||
log.Debug("user authenticated", "user", user.ID, "method", "oauth") | ||
return user, nil | ||
} |
Oops, something went wrong.