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

Add sync routes for v3.7 #262

Merged
merged 2 commits into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions internal/app/claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ type UserClaims struct {
type Auth0profile struct {
UserID string `json:"UserID"`
IsSocial bool
ClientID string `json:"ClientID"`
ClientID string `json:"ClientID,omitempty"`
Connection string
Name string `json:"Name"`
Nickname string `json:"NickName"`
GivenName string
FamilyName string
Email string
EmailVerified bool
Picture string
Picture string `json:"Picture,omitempty"`
CreatedAt time.Time
UpdatedAt time.Time
}
Expand Down
41 changes: 33 additions & 8 deletions internal/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import (
"bytes"
"crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -152,20 +153,30 @@ func (app *App) newUserToken(c *gin.Context) {
}
scopesStr := strings.Join(scopes, " ")
log.Info("setting scopes: ", scopesStr)

jti := make([]byte, 3)
_, err = rand.Read(jti)
if err != nil {
badReq(c, err.Error())
return
}
jti = append([]byte{'r', 'M', '-'}, jti...)
jti = append(jti, '/', 'E')

now := time.Now()
expirationTime := now.Add(24 * time.Hour)
expirationTime := now.Add(3 * time.Hour)
claims := &UserClaims{
Profile: Auth0profile{
UserID: deviceToken.UserID,
IsSocial: false,
Connection: "Username-Password-Authentication",
Name: user.Name,
Name: user.Email,
Nickname: user.Nickname,
GivenName: user.Name,
Email: fmt.Sprintf("%s (via %s)", user.Email, app.cfg.StorageURL),
EmailVerified: true,
Picture: "image.png",
CreatedAt: time.Now(),
UpdatedAt: time.Now(),
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
},
DeviceDesc: deviceToken.DeviceDesc,
DeviceID: deviceToken.DeviceID,
Expand All @@ -175,10 +186,9 @@ func (app *App) newUserToken(c *gin.Context) {
ExpiresAt: expirationTime.Unix(),
NotBefore: now.Unix(),
IssuedAt: now.Unix(),
Subject: "rM User Token",
Subject: deviceToken.UserID,
Issuer: "rM WebApp",
Id: user.ID,
Audience: APIUsage,
Id: base64.StdEncoding.EncodeToString(jti),
},
Version: tokenVersion,
}
Expand Down Expand Up @@ -749,6 +759,21 @@ func (app *App) syncGetRootV3(c *gin.Context) {
})
}

func (app *App) blobStorageRead(c *gin.Context) {
uid := c.GetString(userIDKey)
blobID := common.ParamS(fileKey, c)

reader, _, size, err := app.blobStorer.LoadBlob(uid, blobID)
if err != nil {
log.Error(err)
c.AbortWithStatus(http.StatusInternalServerError)
return
}
defer reader.Close()

c.DataFromReader(http.StatusOK, size, "application/octet-stream", reader, nil)
}

func (app *App) integrationsGetMetadata(c *gin.Context) {
var metadata messages.IntegrationMetadata
metadata.Thumbnail = ""
Expand Down
11 changes: 6 additions & 5 deletions internal/app/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
)

const (
authLog = "[auth-middleware]"
requestLog = "[requestlogging-middleware]"
syncDefault = "sync:default"
syncNew = "sync:tortoise"
authLog = "[auth-middleware]"
requestLog = "[requestlogging-middleware]"
syncDefault = "sync:default"
syncNew = "sync:tortoise"
syncNewLimited = "sync:fox" // Display cloud limit messages
)

func (app *App) authMiddleware() gin.HandlerFunc {
Expand All @@ -35,7 +36,7 @@ func (app *App) authMiddleware() gin.HandlerFunc {

var isSync15 = false
for _, s := range scopes {
if s == syncNew {
if s == syncNew || s == syncNewLimited {
isSync15 = true
break
}
Expand Down
1 change: 1 addition & 0 deletions internal/app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,6 @@ func (app *App) registerRoutes(router *gin.Engine) {

authRoutes.GET("/sync/v3/root", app.syncGetRootV3)
authRoutes.PUT("/sync/v3/root", app.syncUpdateRootV3)
authRoutes.GET("/sync/v3/files/:"+fileKey, app.blobStorageRead)
}
}
Loading