Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeneas Rekkas (arekkas) committed Aug 6, 2016
1 parent f41216c commit 86f527b
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 53 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ id tokens, ...
* There is now a scope matching strategy that can be replaced.
* OAuth2 Client scopes are now checked on every grant type.
* Handler subpackages such as `core/client` or `oidc/explicit` have been merged and moved one level up
* `handler/oidc` is now `handler/openid`
* `handler/core` is now `handler/oauth2`

## 0.1.0

Expand Down
20 changes: 10 additions & 10 deletions compose/compose_oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func OAuth2AuthorizeExplicitFactory(config *Config, storage interface{}, strateg
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
CoreValidator: &oauth2.CoreValidator{
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
}
Expand All @@ -45,8 +45,8 @@ func OAuth2ClientCredentialsGrantFactory(config *Config, storage interface{}, st
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
CoreValidator: &oauth2.CoreValidator{
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
}
Expand All @@ -66,8 +66,8 @@ func OAuth2RefreshTokenGrantFactory(config *Config, storage interface{}, strateg
AccessTokenLifespan: config.GetAccessTokenLifespan(),
},
CoreValidator: &oauth2.CoreValidator{
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
}
Expand All @@ -87,8 +87,8 @@ func OAuth2AuthorizeImplicitFactory(config *Config, storage interface{}, strateg
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
CoreValidator: &oauth2.CoreValidator{
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
}
Expand All @@ -111,8 +111,8 @@ func OAuth2ResourceOwnerPasswordCredentialsFactory(config *Config, storage inter
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
CoreValidator: &oauth2.CoreValidator{
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
CoreStrategy: strategy.(oauth2.CoreStrategy),
CoreStorage: storage.(oauth2.CoreStorage),
ScopeStrategy: fosite.HierarchicScopeStrategy,
},
}
Expand Down
7 changes: 3 additions & 4 deletions fosite-example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/ory-am/fosite"
"github.com/ory-am/fosite/compose"
helpers "github.com/ory-am/fosite/fosite-example/pkg"
core "github.com/ory-am/fosite/handler/oauth2"
"github.com/ory-am/fosite/handler/openid"
"github.com/ory-am/fosite/token/jwt"
"github.com/pkg/errors"
goauth "golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
core "github.com/ory-am/fosite/handler/oauth2"
"github.com/ory-am/fosite/handler/openid"
)

// This is an exemplary storage instance. We will add a client and a user to it so we can use these later on.
Expand Down Expand Up @@ -185,10 +185,9 @@ func authEndpoint(rw http.ResponseWriter, req *http.Request) {
return
}

// we allow issuing of refresh tokens, id tokens and access to "photos" per default
// let's see what scopes the user gave consent to
for _, scope := range req.PostForm["scopes"] {
ar.GrantScope(scope)

}

// Now that the user is authorized, we set up a session:
Expand Down
9 changes: 5 additions & 4 deletions fosite-example/pkg/handler_app_callback.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package store

import (
"github.com/parnurzeal/gorequest"
"net/url"
"fmt"
"net/http"
"net/url"

"github.com/parnurzeal/gorequest"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -72,9 +73,9 @@ func CallbackHandler(c oauth2.Config) func(rw http.ResponseWriter, req *http.Req
<code>%s</code>
</li>
</ul>`,
"/protected-api?token=" + token.AccessToken,
"/protected-api?token="+token.AccessToken,
token.AccessToken,
"?refresh=" + url.QueryEscape(token.RefreshToken),
"?refresh="+url.QueryEscape(token.RefreshToken),
token.RefreshToken,
token,
)))
Expand Down
7 changes: 4 additions & 3 deletions fosite-example/pkg/handler_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store
import (
"fmt"
"net/http"

"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -30,10 +31,10 @@ func HomeHandler(c oauth2.Config) func(rw http.ResponseWriter, req *http.Request
<a href="%s">Make an invalid request</a>
</li>
</ul>`,
c.AuthCodeURL("some-random-state-foobar") + "&nonce=some-random-nonce",
c.AuthCodeURL("some-random-state-foobar")+"&nonce=some-random-nonce",
"http://localhost:3846/auth?client_id=my-client&redirect_uri=http%3A%2F%2Flocalhost%3A3846%2Fcallback&response_type=token%20id_token&scope=fosite%20openid&state=some-random-state-foobar&nonce=some-random-nonce",
c.AuthCodeURL("some-random-state-foobar") + "&nonce=some-random-nonce",
c.AuthCodeURL("some-random-state-foobar")+"&nonce=some-random-nonce",
"/auth?client_id=my-client&scope=fosite&response_type=123&redirect_uri=http://localhost:3846/callback",
)))
}
}
}
3 changes: 2 additions & 1 deletion fosite-example/pkg/handler_oauth2_client_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store
import (
"fmt"
"net/http"

"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
)
Expand All @@ -18,4 +19,4 @@ func ClientEndpoint(c clientcredentials.Config) func(rw http.ResponseWriter, req
rw.Write([]byte(fmt.Sprintf(`<p>Awesome, you just received an access token!<br><br>%s<br><br><strong>more info:</strong><br><br>%s</p>`, token.AccessToken, token)))
rw.Write([]byte(`<p><a href="/">Go back</a></p>`))
}
}
}
3 changes: 2 additions & 1 deletion fosite-example/pkg/handler_oauth2_owner_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package store
import (
"fmt"
"net/http"

"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -37,4 +38,4 @@ func OwnerHandler(c oauth2.Config) func(rw http.ResponseWriter, req *http.Reques
rw.Write([]byte(fmt.Sprintf(`<p>Awesome, you just received an access token!<br><br>%s<br><br><strong>more info:</strong><br><br>%s</p>`, token.AccessToken, token)))
rw.Write([]byte(`<p><a href="/">Go back</a></p>`))
}
}
}
17 changes: 9 additions & 8 deletions handler/oauth2/flow_authorize_code_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,33 @@ package oauth2

import (
"net/http"
"time"
"strings"
"time"

"fmt"

"github.com/ory-am/fosite"
"github.com/pkg/errors"
"golang.org/x/net/context"
"fmt"
)

// AuthorizeExplicitGrantTypeHandler is a response handler for the Authorize Code grant using the explicit grant type
// as defined in https://tools.ietf.org/html/rfc6749#section-4.1
type AuthorizeExplicitGrantHandler struct {
AccessTokenStrategy AccessTokenStrategy
RefreshTokenStrategy RefreshTokenStrategy
AuthorizeCodeStrategy AuthorizeCodeStrategy
AccessTokenStrategy AccessTokenStrategy
RefreshTokenStrategy RefreshTokenStrategy
AuthorizeCodeStrategy AuthorizeCodeStrategy

// AuthorizeCodeGrantStorage is used to persist session data across requests.
AuthorizeCodeGrantStorage AuthorizeCodeGrantStorage

// AuthCodeLifespan defines the lifetime of an authorize code.
AuthCodeLifespan time.Duration
AuthCodeLifespan time.Duration

// AccessTokenLifespan defines the lifetime of an access token.
AccessTokenLifespan time.Duration
AccessTokenLifespan time.Duration

ScopeStrategy fosite.ScopeStrategy
ScopeStrategy fosite.ScopeStrategy
}

func (c *AuthorizeExplicitGrantHandler) HandleAuthorizeEndpointRequest(ctx context.Context, req *http.Request, ar fosite.AuthorizeRequester, resp fosite.AuthorizeResponder) error {
Expand Down
15 changes: 8 additions & 7 deletions handler/oauth2/flow_authorize_implicit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package oauth2

import (
"net/http"
"time"
"strconv"
"strings"

"time"

"fmt"

"github.com/ory-am/fosite"
"github.com/pkg/errors"
"golang.org/x/net/context"
"github.com/ory-am/fosite"
"fmt"
)

// AuthorizeImplicitGrantTypeHandler is a response handler for the Authorize Code grant using the implicit grant type
Expand All @@ -18,12 +19,12 @@ type AuthorizeImplicitGrantTypeHandler struct {
AccessTokenStrategy AccessTokenStrategy

// ImplicitGrantStorage is used to persist session data across requests.
AccessTokenStorage AccessTokenStorage
AccessTokenStorage AccessTokenStorage

// AccessTokenLifespan defines the lifetime of an access token.
AccessTokenLifespan time.Duration

ScopeStrategy fosite.ScopeStrategy
ScopeStrategy fosite.ScopeStrategy
}

func (c *AuthorizeImplicitGrantTypeHandler) HandleAuthorizeEndpointRequest(ctx context.Context, req *http.Request, ar fosite.AuthorizeRequester, resp fosite.AuthorizeResponder) error {
Expand Down Expand Up @@ -63,7 +64,7 @@ func (c *AuthorizeImplicitGrantTypeHandler) IssueImplicitAccessToken(ctx context
}

resp.AddFragment("access_token", token)
resp.AddFragment("expires_in", strconv.Itoa(int(c.AccessTokenLifespan / time.Second)))
resp.AddFragment("expires_in", strconv.Itoa(int(c.AccessTokenLifespan/time.Second)))
resp.AddFragment("token_type", "bearer")
resp.AddFragment("state", ar.GetState())
resp.AddFragment("scope", strings.Join(ar.GetGrantedScopes(), "+"))
Expand Down
2 changes: 1 addition & 1 deletion handler/oauth2/flow_authorize_implicit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestAuthorizeImplicit_EndpointHandler(t *testing.T) {
store.EXPECT().CreateAccessTokenSession(nil, "ats", areq).AnyTimes().Return(nil)

aresp.EXPECT().AddFragment("access_token", "access.ats")
aresp.EXPECT().AddFragment("expires_in", strconv.Itoa(int(h.AccessTokenLifespan / time.Second)))
aresp.EXPECT().AddFragment("expires_in", strconv.Itoa(int(h.AccessTokenLifespan/time.Second)))
aresp.EXPECT().AddFragment("token_type", "bearer")
aresp.EXPECT().AddFragment("state", "state")
aresp.EXPECT().AddFragment("scope", "scope")
Expand Down
3 changes: 2 additions & 1 deletion handler/oauth2/flow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package oauth2
import (
"net/http"

"fmt"

"github.com/ory-am/fosite"
"github.com/pkg/errors"
"golang.org/x/net/context"
"fmt"
)

type ClientCredentialsGrantHandler struct {
Expand Down
4 changes: 2 additions & 2 deletions handler/oauth2/flow_refresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import (
)

type RefreshTokenGrantHandler struct {
AccessTokenStrategy AccessTokenStrategy
AccessTokenStrategy AccessTokenStrategy

RefreshTokenStrategy RefreshTokenStrategy

// RefreshTokenGrantStorage is used to persist session data across requests.
RefreshTokenGrantStorage RefreshTokenGrantStorage

// AccessTokenLifespan defines the lifetime of an access token.
AccessTokenLifespan time.Duration
AccessTokenLifespan time.Duration
}

// HandleTokenEndpointRequest implements https://tools.ietf.org/html/rfc6749#section-6
Expand Down
5 changes: 3 additions & 2 deletions handler/oauth2/flow_resource_owner.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ package oauth2
import (
"net/http"

"fmt"

"github.com/ory-am/fosite"
"github.com/pkg/errors"
"golang.org/x/net/context"
"fmt"
)

type ResourceOwnerPasswordCredentialsGrantHandler struct {
// ResourceOwnerPasswordCredentialsGrantStorage is used to persist session data across requests.
ResourceOwnerPasswordCredentialsGrantStorage ResourceOwnerPasswordCredentialsGrantStorage

ScopeStrategy fosite.ScopeStrategy
ScopeStrategy fosite.ScopeStrategy

*HandleHelper
}
Expand Down
2 changes: 1 addition & 1 deletion handler/oauth2/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"net/http"
"time"

"golang.org/x/net/context"
"github.com/ory-am/fosite"
"golang.org/x/net/context"
)

type HandleHelper struct {
Expand Down
3 changes: 2 additions & 1 deletion handler/oauth2/validator.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package oauth2

import (
"fmt"

"github.com/ory-am/fosite"
"github.com/pkg/errors"
"golang.org/x/net/context"
"fmt"
)

type CoreValidator struct {
Expand Down
2 changes: 1 addition & 1 deletion handler/openid/flow_explicit_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package openid
import (
"net/http"

"github.com/ory-am/fosite"
"github.com/pkg/errors"
"golang.org/x/net/context"
"github.com/ory-am/fosite"
)

func (c *OpenIDConnectExplicitHandler) HandleTokenEndpointRequest(ctx context.Context, r *http.Request, request fosite.AccessRequester) error {
Expand Down
5 changes: 3 additions & 2 deletions handler/openid/flow_hybrid.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package openid
import (
"net/http"

"fmt"

"github.com/ory-am/fosite"
"github.com/ory-am/fosite/handler/oauth2"
"github.com/ory-am/fosite/token/jwt"
"github.com/pkg/errors"
"golang.org/x/net/context"
"github.com/ory-am/fosite"
"fmt"
)

type OpenIDConnectHybridHandler struct {
Expand Down
7 changes: 4 additions & 3 deletions handler/openid/flow_implicit.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package openid
import (
"net/http"

"fmt"

"github.com/ory-am/fosite"
"github.com/ory-am/fosite/handler/oauth2"
"github.com/ory-am/fosite/token/jwt"
"github.com/pkg/errors"
"golang.org/x/net/context"
"github.com/ory-am/fosite"
"github.com/ory-am/fosite/handler/oauth2"
"fmt"
)

type OpenIDConnectImplicitHandler struct {
Expand Down
2 changes: 1 addition & 1 deletion handler/openid/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package openid
import (
"net/http"

"golang.org/x/net/context"
"github.com/ory-am/fosite"
"golang.org/x/net/context"
)

type IDTokenHandleHelper struct {
Expand Down

0 comments on commit 86f527b

Please sign in to comment.