Skip to content
This repository has been archived by the owner on Jan 27, 2021. It is now read-only.

Add numeric uid and gid to the access token #89

Merged
merged 2 commits into from
Aug 19, 2020
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
5 changes: 5 additions & 0 deletions changelog/unreleased/mint-uid-and-gid.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Add numeric uid and gid to the access token

The eos storage driver is fetching the uid and gid of a user from the access token. This PR is using the response of the accounts service to mint them in the token.

https://github.com/owncloud/ocis-proxy/pull/89
20 changes: 18 additions & 2 deletions pkg/middleware/account_uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"fmt"
"net/http"
"strconv"
"strings"

revauser "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
types "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/pkg/token/manager/jwt"
acc "github.com/owncloud/ocis-accounts/pkg/proto/v0"
"github.com/owncloud/ocis-pkg/v2/log"
Expand Down Expand Up @@ -145,7 +147,7 @@ func AccountUUID(opts ...Option) func(next http.Handler) http.Handler {
}

l.Debug().Interface("claims", claims).Interface("account", account).Msgf("Associated claims with uuid")
token, err := tokenManager.MintToken(r.Context(), &revauser.User{
user := &revauser.User{
Id: &revauser.UserId{
OpaqueId: account.Id,
Idp: claims.Iss,
Expand All @@ -155,7 +157,21 @@ func AccountUUID(opts ...Option) func(next http.Handler) http.Handler {
Mail: account.Mail,
MailVerified: account.ExternalUserState == "" || account.ExternalUserState == "Accepted",
Groups: groups,
})
Opaque: &types.Opaque{
Map: map[string]*types.OpaqueEntry{},
},
}

user.Opaque.Map["uid"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(strconv.FormatInt(account.UidNumber, 10)),
}
user.Opaque.Map["gid"] = &types.OpaqueEntry{
Decoder: "plain",
Value: []byte(strconv.FormatInt(account.GidNumber, 10)),
}

token, err := tokenManager.MintToken(r.Context(), user)

if err != nil {
l.Error().Err(err).Msgf("Could not mint token")
Expand Down