03ea72595d
* Initial Commit for OAuth API This builds and run and return the right error. Need to test it and then adding all users as possible client * Added mising dependency * just compile already... * Fixing template test * Imrpovements Moved db stuff in models Added some tests Added form in modpanel to add/update a client Added controllers for add/update of client * Added Forms + speed improvements Controller oauth client listing + html Controller oauth client delete + messages Messages on comment delete New ES config that disable ES if set to false. Improve load speed on local development Fix a load config bug Fix index admin & translation string sign_out broken by @ewhal * Sanitize empty strig in form array + css Multiple empty array of strings are sanitized for the oauth client create form Added some css for the form display * Upload and Create form works * Fix splitting response types * Removing required on secret when updating * fix travis error * Fix travis template test * Update dependency * Moved to jinzhu instead of azhao * randomizen secret on creation * Final touch on oath api improved display name fix grant form csrf fix login csrf on oauth * Fix gorm test * fix template test * Fixing deleted dependency issue * Make travis faster * Fix typo * Fix csrf for api calls * This shouldn't be exempt * Removing hard coded hash @ewhal Don't forget to replace the hash in tokens.go with another one * Added an example on how to use OAuth middleware * Renamed fosite utils to oauth2 utils
102 lignes
4,9 Kio
Go
102 lignes
4,9 Kio
Go
package compose
|
|
|
|
import (
|
|
"github.com/ory/fosite/handler/oauth2"
|
|
)
|
|
|
|
// OAuth2AuthorizeExplicitFactory creates an OAuth2 authorize code grant ("authorize explicit flow") handler and registers
|
|
// an access token, refresh token and authorize code validator.
|
|
func OAuth2AuthorizeExplicitFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
|
|
return &oauth2.AuthorizeExplicitGrantHandler{
|
|
AccessTokenStrategy: strategy.(oauth2.AccessTokenStrategy),
|
|
RefreshTokenStrategy: strategy.(oauth2.RefreshTokenStrategy),
|
|
AuthorizeCodeStrategy: strategy.(oauth2.AuthorizeCodeStrategy),
|
|
CoreStorage: storage.(oauth2.CoreStorage),
|
|
AuthCodeLifespan: config.GetAuthorizeCodeLifespan(),
|
|
AccessTokenLifespan: config.GetAccessTokenLifespan(),
|
|
ScopeStrategy: config.GetScopeStrategy(),
|
|
}
|
|
}
|
|
|
|
// OAuth2ClientCredentialsGrantFactory creates an OAuth2 client credentials grant handler and registers
|
|
// an access token, refresh token and authorize code validator.
|
|
func OAuth2ClientCredentialsGrantFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
|
|
return &oauth2.ClientCredentialsGrantHandler{
|
|
HandleHelper: &oauth2.HandleHelper{
|
|
AccessTokenStrategy: strategy.(oauth2.AccessTokenStrategy),
|
|
AccessTokenStorage: storage.(oauth2.AccessTokenStorage),
|
|
AccessTokenLifespan: config.GetAccessTokenLifespan(),
|
|
},
|
|
ScopeStrategy: config.GetScopeStrategy(),
|
|
}
|
|
}
|
|
|
|
// OAuth2RefreshTokenGrantFactory creates an OAuth2 refresh grant handler and registers
|
|
// an access token, refresh token and authorize code validator.
|
|
func OAuth2RefreshTokenGrantFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
|
|
return &oauth2.RefreshTokenGrantHandler{
|
|
AccessTokenStrategy: strategy.(oauth2.AccessTokenStrategy),
|
|
RefreshTokenStrategy: strategy.(oauth2.RefreshTokenStrategy),
|
|
TokenRevocationStorage: storage.(oauth2.TokenRevocationStorage),
|
|
AccessTokenLifespan: config.GetAccessTokenLifespan(),
|
|
}
|
|
}
|
|
|
|
// OAuth2AuthorizeImplicitFactory creates an OAuth2 implicit grant ("authorize implicit flow") handler and registers
|
|
// an access token, refresh token and authorize code validator.
|
|
func OAuth2AuthorizeImplicitFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
|
|
return &oauth2.AuthorizeImplicitGrantTypeHandler{
|
|
AccessTokenStrategy: strategy.(oauth2.AccessTokenStrategy),
|
|
AccessTokenStorage: storage.(oauth2.AccessTokenStorage),
|
|
AccessTokenLifespan: config.GetAccessTokenLifespan(),
|
|
ScopeStrategy: config.GetScopeStrategy(),
|
|
}
|
|
}
|
|
|
|
// OAuth2ResourceOwnerPasswordCredentialsFactory creates an OAuth2 resource owner password credentials grant handler and registers
|
|
// an access token, refresh token and authorize code validator.
|
|
func OAuth2ResourceOwnerPasswordCredentialsFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
|
|
return &oauth2.ResourceOwnerPasswordCredentialsGrantHandler{
|
|
ResourceOwnerPasswordCredentialsGrantStorage: storage.(oauth2.ResourceOwnerPasswordCredentialsGrantStorage),
|
|
HandleHelper: &oauth2.HandleHelper{
|
|
AccessTokenStrategy: strategy.(oauth2.AccessTokenStrategy),
|
|
AccessTokenStorage: storage.(oauth2.AccessTokenStorage),
|
|
AccessTokenLifespan: config.GetAccessTokenLifespan(),
|
|
},
|
|
RefreshTokenStrategy: strategy.(oauth2.RefreshTokenStrategy),
|
|
ScopeStrategy: config.GetScopeStrategy(),
|
|
}
|
|
}
|
|
|
|
// OAuth2TokenRevocationFactory creates an OAuth2 token revocation handler.
|
|
func OAuth2TokenRevocationFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
|
|
return &oauth2.TokenRevocationHandler{
|
|
TokenRevocationStorage: storage.(oauth2.TokenRevocationStorage),
|
|
AccessTokenStrategy: strategy.(oauth2.AccessTokenStrategy),
|
|
RefreshTokenStrategy: strategy.(oauth2.RefreshTokenStrategy),
|
|
}
|
|
}
|
|
|
|
// OAuth2TokenIntrospectionFactory creates an OAuth2 token introspection handler and registers
|
|
// an access token and refresh token validator.
|
|
func OAuth2TokenIntrospectionFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
|
|
return &oauth2.CoreValidator{
|
|
CoreStrategy: strategy.(oauth2.CoreStrategy),
|
|
CoreStorage: storage.(oauth2.CoreStorage),
|
|
ScopeStrategy: config.GetScopeStrategy(),
|
|
}
|
|
}
|
|
|
|
// OAuth2StatelessJWTIntrospectionFactory creates an OAuth2 token introspection handler and
|
|
// registers an access token validator. This can only be used to validate JWTs and does so
|
|
// statelessly, meaning it uses only the data available in the JWT itself, and does not access the
|
|
// storage implementation at all.
|
|
//
|
|
// Due to the stateless nature of this factory, THE BUILT-IN REVOCATION MECHANISMS WILL NOT WORK.
|
|
// If you need revocation, you can validate JWTs statefully, using the other factories.
|
|
func OAuth2StatelessJWTIntrospectionFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
|
|
return &oauth2.StatelessJWTValidator{
|
|
JWTAccessTokenStrategy: strategy.(oauth2.JWTAccessTokenStrategy),
|
|
ScopeStrategy: config.GetScopeStrategy(),
|
|
}
|
|
}
|