Skip to content

Commit

Permalink
Merge pull request #214 from DIMO-Network/feature/si-2529-add-audienc…
Browse files Browse the repository at this point in the history
…e-to-privilege-tokens

Adds audience field to sign token messages.
  • Loading branch information
KevinJoiner authored Apr 2, 2024
2 parents b57098b + b61703e commit 3b70843
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 88 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18
go-version: "1.20"

- name: Checkout code
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GOLANGCI_VERSION = 1.52.0
GOTESTSUM_VERSION ?= 1.9.0

PROTOC_VERSION = 21.12
PROTOC_GEN_GO_VERSION = 1.28.1
PROTOC_GEN_GO_VERSION = 1.30.0
PROTOC_GEN_GO_GRPC_VERSION = 1.3.0

KIND_VERSION = 0.17.0
Expand Down
128 changes: 69 additions & 59 deletions api/v2/api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/v2/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ message SignTokenResp {
message SignTokenReq {
string subject = 1;
google.protobuf.Struct custom_claims = 2;
repeated string audience = 3;
}

// Dex represents the dex gRPC service.
Expand Down
10 changes: 6 additions & 4 deletions connector/web3/web3.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ package web3
import (
"errors"
"fmt"
"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"

"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/pkg/log"
)

type Config struct {
Expand Down Expand Up @@ -136,6 +138,6 @@ func signHash(data []byte) []byte {
return accounts.TextHash(data)
}

func createEthClient(rpcUrl string) (bind.ContractBackend, error) {
return ethclient.Dial(rpcUrl)
func createEthClient(rpcURL string) (bind.ContractBackend, error) {
return ethclient.Dial(rpcURL)
}
8 changes: 5 additions & 3 deletions connector/web3/web3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"github.com/dexidp/dex/connector"
"math/big"
"testing"

"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
Expand All @@ -14,8 +16,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"math/big"
"testing"

"github.com/dexidp/dex/connector"
)

type BkTest struct {
Expand Down
1 change: 1 addition & 0 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ func (d dexAPI) SignToken(ctx context.Context, req *api.SignTokenReq) (*api.Sign
"iat": issuedAt.Unix(),
"exp": expiry.Unix(),
"iss": d.serverConfig.Issuer,
"aud": req.Audience,
}

claims := req.CustomClaims.AsMap()
Expand Down
20 changes: 1 addition & 19 deletions server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@ import (
"crypto/subtle"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/ethclient"
"html/template"
"math/big"
"net/http"
"net/url"
"os"
"path"
"regexp"
"sort"
Expand All @@ -26,12 +22,12 @@ import (
"github.com/coreos/go-oidc/v3/oidc"
"github.com/ethereum/go-ethereum/common"
"github.com/gorilla/mux"
"github.com/spruceid/siwe-go"
jose "gopkg.in/square/go-jose.v2"

"github.com/dexidp/dex/connector"
"github.com/dexidp/dex/server/internal"
"github.com/dexidp/dex/storage"
"github.com/spruceid/siwe-go"
)

const (
Expand Down Expand Up @@ -270,7 +266,6 @@ func (s *Server) handleGenerateChallenge(w http.ResponseWriter, r *http.Request)

siweMessage, err := siwe.InitMessage(s.issuerURL.Host, addr.Hex(), s.issuerURL.String(), nonce, options)
if err != nil {
//asd
s.renderErrorJSON(w, http.StatusInternalServerError, err.Error())
return
}
Expand Down Expand Up @@ -1892,16 +1887,3 @@ func usernamePrompt(conn connector.PasswordConnector) string {
}
return "Username"
}

func createEthClient() (bind.ContractBackend, error) {
rpcUrl := os.Getenv("ETH_RPC_CLIENT")
if rpcUrl != "" {
client, err := ethclient.Dial(rpcUrl)
if err != nil {
return nil, err
}
return client, nil
}

return nil, errors.New("could not initialize eth client with url")
}
2 changes: 1 addition & 1 deletion server/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func tokenErr(w http.ResponseWriter, typ, description string, statusCode int) er
return nil
}

// nolint
//nolint
const (
errInvalidRequest = "invalid_request"
errUnauthorizedClient = "unauthorized_client"
Expand Down

0 comments on commit 3b70843

Please sign in to comment.