support access token via query params

This commit is contained in:
David Zhao
2020-12-27 23:04:20 -08:00
parent 3fb606236e
commit 60f2596983
3 changed files with 11 additions and 3 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ func joinRoom(c *cli.Context) error {
} else { } else {
// dev mode, will pass these as overrides // dev mode, will pass these as overrides
v := url.Values{} v := url.Values{}
v.Set("room_id", roomId) v.Set("room", roomId)
v.Set("name", name) v.Set("name", name)
u.RawQuery = v.Encode() u.RawQuery = v.Encode()
} }
+9 -1
View File
@@ -15,6 +15,7 @@ const (
authorizationHeader = "Authorization" authorizationHeader = "Authorization"
bearerPrefix = "Bearer " bearerPrefix = "Bearer "
grantsKey = "grants" grantsKey = "grants"
accessTokenParam = "access_token"
) )
var ( var (
@@ -35,6 +36,7 @@ func NewAPIKeyAuthMiddleware(provider auth.KeyProvider) *APIKeyAuthMiddleware {
func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) { func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
authHeader := r.Header.Get(authorizationHeader) authHeader := r.Header.Get(authorizationHeader)
var authToken string
if authHeader != "" { if authHeader != "" {
if !strings.HasPrefix(authHeader, bearerPrefix) { if !strings.HasPrefix(authHeader, bearerPrefix) {
@@ -43,7 +45,13 @@ func (m *APIKeyAuthMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request,
return return
} }
authToken := authHeader[len(bearerPrefix):] authToken = authHeader[len(bearerPrefix):]
} else {
// attempt to find from request header
authToken = r.FormValue(accessTokenParam)
}
if authToken != "" {
v, err := auth.ParseAPIToken(authToken) v, err := auth.ParseAPIToken(authToken)
if err != nil { if err != nil {
w.WriteHeader(http.StatusUnauthorized) w.WriteHeader(http.StatusUnauthorized)
+1 -1
View File
@@ -38,7 +38,7 @@ func NewRTCService(conf *config.Config, manager *rtc.RoomManager) *RTCService {
} }
func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
roomId := r.FormValue("room_id") roomId := r.FormValue("room")
var pName string var pName string
if s.isDev { if s.isDev {
r.FormValue("name") r.FormValue("name")