Skip to content

Commit 95ff77d

Browse files
authored
0.3.0 (#195)
* cmd: resolve broken formatting issue * client: field scopes should be scope * config: fix broken system secret method and add test case for it * client: scope should be scope in rethinkdb too * client: scope should be scope in rethinkdb too * oauth2: resolve import paths broken by goimports
1 parent a297f7e commit 95ff77d

File tree

9 files changed

+94
-23
lines changed

9 files changed

+94
-23
lines changed

client/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package client
22

33
import (
4-
"github.com/ory-am/fosite"
54
"strings"
5+
6+
"github.com/ory-am/fosite"
67
)
78

89
type Client struct {
@@ -12,7 +13,7 @@ type Client struct {
1213
RedirectURIs []string `json:"redirect_uris" gorethink:"redirect_uris"`
1314
GrantTypes []string `json:"grant_types" gorethink:"grant_types"`
1415
ResponseTypes []string `json:"response_types" gorethink:"response_types"`
15-
Scopes string `json:"scopes" gorethink:"scopes"`
16+
Scope string `json:"scope" gorethink:"scope"`
1617
Owner string `json:"owner" gorethink:"owner"`
1718
PolicyURI string `json:"policy_uri" gorethink:"policy_uri"`
1819
TermsOfServiceURI string `json:"tos_uri" gorethink:"tos_uri"`
@@ -34,7 +35,7 @@ func (c *Client) GetHashedSecret() []byte {
3435
}
3536

3637
func (c *Client) GetScopes() fosite.Arguments {
37-
return fosite.Arguments(strings.Split(c.Scopes, " "))
38+
return fosite.Arguments(strings.Split(c.Scope, " "))
3839
}
3940

4041
func (c *Client) GetGrantTypes() fosite.Arguments {

cmd/cli/handler_client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"fmt"
66
"os"
77

8+
"strings"
9+
810
"github.com/ory-am/hydra/client"
911
"github.com/ory-am/hydra/config"
1012
"github.com/ory-am/hydra/pkg"
1113
"github.com/spf13/cobra"
12-
"strings"
1314
)
1415

1516
type ClientHandler struct {
@@ -70,7 +71,7 @@ func (h *ClientHandler) CreateClient(cmd *cobra.Command, args []string) {
7071
ID: id,
7172
Secret: string(secret),
7273
ResponseTypes: responseTypes,
73-
Scopes: strings.Join(allowedScopes, " "),
74+
Scope: strings.Join(allowedScopes, " "),
7475
GrantTypes: grantTypes,
7576
RedirectURIs: callbacks,
7677
Name: name,

cmd/server/helper_client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (h *Handler) createRootIfNewInstall(c *config.Config) {
4242
Name: "This temporary client is generated by hydra and is granted all of hydra's administrative privileges. It must be removed when everything is set up.",
4343
ResponseTypes: []string{"id_token", "code", "token"},
4444
GrantTypes: []string{"implicit", "refresh_token", "authorization_code", "password", "client_credentials"},
45-
Scopes: "hydra openid offline",
45+
Scope: "hydra openid offline",
4646
RedirectURIs: []string{"http://localhost:4445/callback"},
4747
Secret: secret,
4848
}
@@ -63,8 +63,8 @@ func (h *Handler) createRootIfNewInstall(c *config.Config) {
6363

6464
logrus.Infoln("Temporary root client created.")
6565
if forceRoot == "" {
66-
logrus.Infoln("client_id: %s", root.GetID())
67-
logrus.Infoln("client_secret: %s", string(secret))
66+
logrus.Infof("client_id: %s", root.GetID())
67+
logrus.Infof("client_secret: %s", string(secret))
6868
logrus.Warn("WARNING: YOU MUST delete this client once in production, as credentials may have been leaked logfiles.")
6969
}
7070
}

config/config.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type Config struct {
5252
cluster *url.URL `yaml:"-"`
5353
oauth2Client *http.Client `yaml:"-"`
5454
context *Context `yaml:"-"`
55+
systemSecret []byte
5556
}
5657

5758
func matchesRange(r *http.Request, ranges []string) error {
@@ -238,11 +239,15 @@ func (c *Config) OAuth2Client(cmd *cobra.Command) *http.Client {
238239
}
239240

240241
func (c *Config) GetSystemSecret() []byte {
242+
if len(c.systemSecret) > 0 {
243+
return c.systemSecret
244+
}
245+
241246
var secret = []byte(c.SystemSecret)
242247
if len(secret) >= 16 {
243248
hash := sha256.Sum256(secret)
244249
secret = hash[:]
245-
c.SystemSecret = string(secret)
250+
c.systemSecret = secret
246251
return secret
247252
}
248253

@@ -254,7 +259,7 @@ func (c *Config) GetSystemSecret() []byte {
254259
logrus.Infof("Generated system secret: %s", secret)
255260
hash := sha256.Sum256(secret)
256261
secret = hash[:]
257-
c.SystemSecret = string(secret)
262+
c.systemSecret = secret
258263
logrus.Warnln("WARNING: DO NOT generate system secrets in production. The secret will be leaked to the logs.")
259264
return secret
260265
}

config/config_test.go

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,72 @@
11
package config
22

3-
import "testing"
3+
import (
4+
"net/http"
5+
"testing"
6+
"time"
7+
8+
"github.com/stretchr/testify/assert"
9+
)
410

511
func TestConfig(t *testing.T) {
612
c := &Config{}
713
_ = c.Context()
14+
15+
assert.Equal(t, c.GetAccessTokenLifespan(), time.Hour)
16+
}
17+
18+
func TestDoesRequestSatisfyTermination(t *testing.T) {
19+
c := &Config{AllowTLSTermination: ""}
20+
assert.NotNil(t, c.DoesRequestSatisfyTermination(new(http.Request)))
21+
22+
c = &Config{AllowTLSTermination: "127.0.0.1/24"}
23+
r := &http.Request{Header: http.Header{}}
24+
assert.NotNil(t, c.DoesRequestSatisfyTermination(r))
25+
26+
r = &http.Request{Header: http.Header{"X-Forwarded-Proto": []string{"http"}}}
27+
assert.NotNil(t, c.DoesRequestSatisfyTermination(r))
28+
29+
r = &http.Request{
30+
RemoteAddr: "227.0.0.1:123",
31+
Header: http.Header{"X-Forwarded-Proto": []string{"https"}},
32+
}
33+
assert.NotNil(t, c.DoesRequestSatisfyTermination(r))
34+
35+
r = &http.Request{
36+
RemoteAddr: "127.0.0.1:123",
37+
Header: http.Header{"X-Forwarded-Proto": []string{"https"}},
38+
}
39+
assert.Nil(t, c.DoesRequestSatisfyTermination(r))
40+
}
41+
42+
func TestSystemSecret(t *testing.T) {
43+
c3 := &Config{}
44+
assert.EqualValues(t, c3.GetSystemSecret(), c3.GetSystemSecret())
45+
c := &Config{SystemSecret: "foobarbazbarasdfasdffoobarbazbarasdfasdf"}
46+
assert.EqualValues(t, c.GetSystemSecret(), c.GetSystemSecret())
47+
c2 := &Config{SystemSecret: "foobarbazbarasdfasdffoobarbazbarasdfasdf"}
48+
assert.EqualValues(t, c.GetSystemSecret(), c2.GetSystemSecret())
49+
}
50+
51+
func TestResolve(t *testing.T) {
52+
c := &Config{ClusterURL: "https://localhost:1234"}
53+
assert.Equal(t, c.Resolve("foo", "bar").String(), "https://localhost:1234/foo/bar")
54+
assert.Equal(t, c.Resolve("/foo", "/bar").String(), "https://localhost:1234/foo/bar")
55+
56+
c = &Config{ClusterURL: "https://localhost:1234/"}
57+
assert.Equal(t, c.Resolve("/foo", "/bar").String(), "https://localhost:1234/foo/bar")
58+
59+
c = &Config{ClusterURL: "https://localhost:1234/bar"}
60+
assert.Equal(t, c.Resolve("/foo", "/bar").String(), "https://localhost:1234/bar/foo/bar")
61+
}
62+
63+
func TestLifespan(t *testing.T) {
64+
assert.Equal(t, (&Config{}).GetAccessTokenLifespan(), time.Hour)
65+
assert.Equal(t, (&Config{AccessTokenLifespan: "6h"}).GetAccessTokenLifespan(), time.Hour*6)
66+
67+
assert.Equal(t, (&Config{}).GetAuthCodeLifespan(), time.Minute*10)
68+
assert.Equal(t, (&Config{AuthCodeLifespan: "15m"}).GetAuthCodeLifespan(), time.Minute*15)
69+
70+
assert.Equal(t, (&Config{}).GetIDTokenLifespan(), time.Hour)
71+
assert.Equal(t, (&Config{IDTokenLifespan: "10s"}).GetIDTokenLifespan(), time.Second*10)
872
}

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
// Hydra is built for high throughput environments. Check out the below siege benchmark on a Macbook Pro Late 2013, connected to RethinkDB validating access tokens.
77
//
88
// The official repository is located at https://github.com/ory-am/hydra
9-
package main
9+
package main

oauth2/consent_strategy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"time"
66

77
"crypto/rsa"
8-
98
"github.com/dgrijalva/jwt-go"
9+
1010
"github.com/go-errors/errors"
1111
"github.com/ory-am/fosite"
1212
"github.com/ory-am/fosite/handler/openid"

oauth2/oauth2_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package oauth2_test
22

33
import (
4-
"net/http/httptest"
5-
"time"
6-
74
"fmt"
5+
"net/http/httptest"
86
"net/url"
7+
"time"
98

9+
"github.com/dgrijalva/jwt-go"
1010
"github.com/go-errors/errors"
1111
"github.com/julienschmidt/httprouter"
1212
"github.com/ory-am/fosite"
@@ -19,7 +19,6 @@ import (
1919
"github.com/ory-am/hydra/pkg"
2020
"golang.org/x/oauth2"
2121
"golang.org/x/oauth2/clientcredentials"
22-
"github.com/dgrijalva/jwt-go"
2322
)
2423

2524
var hasher = &hash.BCrypt{}
@@ -87,7 +86,7 @@ func init() {
8786
RedirectURIs: []string{ts.URL + "/callback"},
8887
ResponseTypes: []string{"id_token", "code", "token"},
8988
GrantTypes: []string{"implicit", "refresh_token", "authorization_code", "password", "client_credentials"},
90-
Scopes: "hydra",
89+
Scope: "hydra",
9190
}
9291

9392
c, _ := url.Parse(ts.URL + "/consent")
@@ -100,7 +99,7 @@ func init() {
10099
RedirectURIs: []string{ts.URL + "/callback"},
101100
ResponseTypes: []string{"id_token", "code", "token"},
102101
GrantTypes: []string{"implicit", "refresh_token", "authorization_code", "password", "client_credentials"},
103-
Scopes: "hydra",
102+
Scope: "hydra",
104103
}
105104

106105
oauthConfig = &oauth2.Config{

warden/warden_http.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import (
44
"net/http"
55
"net/url"
66

7+
"bytes"
8+
"encoding/json"
9+
"io/ioutil"
10+
"strconv"
11+
712
"github.com/go-errors/errors"
813
"github.com/ory-am/fosite"
914
"github.com/ory-am/hydra/firewall"
@@ -12,10 +17,6 @@ import (
1217
"golang.org/x/net/context"
1318
"golang.org/x/oauth2"
1419
"golang.org/x/oauth2/clientcredentials"
15-
"bytes"
16-
"io/ioutil"
17-
"strconv"
18-
"encoding/json"
1920
)
2021

2122
type HTTPWarden struct {

0 commit comments

Comments
 (0)