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

Commit

Permalink
Add numeric uid and gid to the access token
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Aug 19, 2020
1 parent d3fd5d5 commit d72f50d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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

0 comments on commit d72f50d

Please sign in to comment.