-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: composable factories, better token validation, better scope hand…
…ling and simplify structure * readme: add gitter chat badge closes #67 * handler: flatten packages closes #70 * openid: don't autogrant openid scope - closes #68 * all: clean up scopes / arguments - closes #66 * all: composable factories - closes #64 * all: refactor token validation - closes #63 * all: remove mandatory scope - closes #62
- Loading branch information
Showing
100 changed files
with
2,038 additions
and
1,594 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
This is a list of breaking changes. As long as `1.0.0` is not released, breaking changes will be addressed as minor version | ||
bumps (`0.1.0` -> `0.2.0`). | ||
|
||
## 0.2.0 | ||
|
||
Breaking changes: | ||
|
||
* Token validation refactored: `ValidateRequestAuthorization` is now `Validate` and does not require a http request | ||
but instead a token and a token hint. A token can be anything, including authorization codes, refresh tokens, | ||
id tokens, ... | ||
* Remove mandatory scope: The mandatory scope (`fosite`) has been removed as it has proven impractical. | ||
* Allowed OAuth2 Client scopes are now being set with `scope` instead of `granted_scopes` when using the DefaultClient. | ||
* 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 | ||
|
||
Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package compose | ||
|
||
import ( | ||
"crypto/rsa" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/ory-am/fosite" | ||
"github.com/ory-am/fosite/hash" | ||
) | ||
|
||
type handler func(config *Config, storage interface{}, strategy interface{}) interface{} | ||
|
||
// Compose takes a config, a storage, a strategy and handlers to instantiate an OAuth2Provider: | ||
// | ||
// import "github.com/ory-am/fosite/compose" | ||
// | ||
// // var storage = new(MyFositeStorage) | ||
// var config = Config { | ||
// AccessTokenLifespan: time.Minute * 30, | ||
// // check Config for further configuration options | ||
// } | ||
// | ||
// var strategy = NewOAuth2HMACStrategy(config) | ||
// | ||
// var oauth2Provider = Compose( | ||
// config, | ||
// storage, | ||
// strategy, | ||
// NewOAuth2AuthorizeExplicitHandler, | ||
// OAuth2ClientCredentialsGrantFactory, | ||
// // for a complete list refer to the docs of this package | ||
// ) | ||
func Compose(config *Config, storage interface{}, strategy interface{}, handlers ...handler) fosite.OAuth2Provider { | ||
f := &fosite.Fosite{ | ||
Store: storage.(fosite.Storage), | ||
AuthorizeEndpointHandlers: fosite.AuthorizeEndpointHandlers{}, | ||
TokenEndpointHandlers: fosite.TokenEndpointHandlers{}, | ||
TokenValidators: fosite.TokenValidators{}, | ||
Hasher: &hash.BCrypt{WorkFactor: config.GetHashCost()}, | ||
Logger: &logrus.Logger{}, | ||
ScopeStrategy: fosite.HierarchicScopeStrategy, | ||
} | ||
|
||
for _, h := range handlers { | ||
res := h(config, storage, strategy) | ||
if ah, ok := res.(fosite.AuthorizeEndpointHandler); ok { | ||
f.AuthorizeEndpointHandlers.Append(ah) | ||
} | ||
if th, ok := res.(fosite.TokenEndpointHandler); ok { | ||
f.TokenEndpointHandlers.Append(th) | ||
} | ||
if tv, ok := res.(fosite.TokenValidator); ok { | ||
f.TokenValidators.Append(tv) | ||
} | ||
} | ||
|
||
return f | ||
} | ||
|
||
// ComposeAllEnabled returns a fosite instance with all OAuth2 and OpenID Connect handlers enabled. | ||
func ComposeAllEnabled(config *Config, storage interface{}, secret []byte, key *rsa.PrivateKey) fosite.OAuth2Provider { | ||
return Compose( | ||
config, | ||
storage, | ||
&CommonStrategy{ | ||
CoreStrategy: NewOAuth2HMACStrategy(config, secret), | ||
OpenIDConnectTokenStrategy: NewOpenIDConnectStrategy(key), | ||
}, | ||
OAuth2AuthorizeExplicitFactory, | ||
OAuth2AuthorizeImplicitFactory, | ||
OAuth2ClientCredentialsGrantFactory, | ||
OAuth2RefreshTokenGrantFactory, | ||
OAuth2ResourceOwnerPasswordCredentialsFactory, | ||
|
||
OpenIDConnectExplicit, | ||
OpenIDConnectImplicit, | ||
OpenIDConnectHybrid, | ||
) | ||
} |
Oops, something went wrong.