Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally accept HTTP key through header in RPC requests. #1097

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ All notable changes to this project are documented below.
The format is based on [keep a changelog](http://keepachangelog.com) and this project uses [semantic versioning](http://semver.org).

## [Unreleased]
### Added
- Allow HTTP key to be read from an HTTP request's Basic auth header if present.

### Changed
- Use Steam partner API instead of public API for Steam profiles and friends requests.

### Fixed
- Fixed multiple issues found by linter.

### Fixed
- Fixes calculation of leaderboard and tournament times for rare types of CRON expressions that don't execute at a fixed interval.
- Improved how start and end times are calculated for tournaments occuring in the future.

Expand Down
33 changes: 23 additions & 10 deletions server/api_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,30 @@ func (s *ApiServer) RpcFuncHttp(w http.ResponseWriter, r *http.Request) {
return
}
} else if auth := r.Header["Authorization"]; len(auth) >= 1 {
var token string
userID, username, vars, expiry, token, isTokenAuth = parseBearerAuth([]byte(s.config.GetSession().EncryptionKey), auth[0])
if !isTokenAuth || !s.sessionCache.IsValidSession(userID, expiry, token) {
// Auth token not valid or expired.
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
_, err := w.Write(authTokenInvalidBytes)
if err != nil {
s.logger.Debug("Error writing response to client", zap.Error(err))
if httpKey, _, ok := parseBasicAuth(auth[0]); ok {
if httpKey != s.config.GetRuntime().HTTPKey {
// HTTP key did not match.
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
_, err := w.Write(httpKeyInvalidBytes)
if err != nil {
s.logger.Debug("Error writing response to client", zap.Error(err))
}
return
}
} else {
var token string
userID, username, vars, expiry, token, isTokenAuth = parseBearerAuth([]byte(s.config.GetSession().EncryptionKey), auth[0])
if !isTokenAuth || !s.sessionCache.IsValidSession(userID, expiry, token) {
// Auth token not valid or expired.
w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusUnauthorized)
_, err := w.Write(authTokenInvalidBytes)
if err != nil {
s.logger.Debug("Error writing response to client", zap.Error(err))
}
return
}
return
}
} else {
// No authentication present.
Expand Down
Loading