oauth2
oauth2 copied to clipboard
Custom grant types
Hi, I would like the ability to extend and implement custom grant types.
My use case is to implement a 'social' grant type like the following lib: https://github.com/coderello/laravel-passport-social-grant
I'm currently porting an oauth implementation for an app into golang and need to emulate the above.
I don't think this is possible currently in go-oauth2, would you be open to it?
there is an example: https://github.com/go2s/o2s/blob/master/http/server.go
captcha.EnableCaptchaAuth(svr, mcs, captcha.CaptchaLogSender)
there is an example: https://github.com/go2s/o2s/blob/master/http/server.go
captcha.EnableCaptchaAuth(svr, mcs, captcha.CaptchaLogSender)
You linked to a different library. Is the suggestion here to implement a new server type that supports the custom grant?
@casimcdaniels he means, that it's possible with wrappers, which redefine some methods
func (s *Oauth2Server) AddCustomerGrantType(grantType oauth2.GrantType, validator GrantTypeRequestValidator, handleConfigurer HandleConfigurer) {
for _, t := range s.Config.AllowedGrantTypes {
if t == grantType {
panic("grant type already exist")
}
}
s.Config.AllowedGrantTypes = append(s.Config.AllowedGrantTypes, grantType)
customGrantRequestValidatorMap[grantType] = validator
if handleConfigurer != nil {
handleConfigurer(s.AddHandler)
}
}
func (s *Oauth2Server) ValidationTokenRequest(r *http.Request) (gt oauth2.GrantType, tgr *oauth2.TokenGenerateRequest, err error) {
gt = oauth2.GrantType(r.FormValue("grant_type"))
if fn, ok := customGrantRequestValidatorMap[gt]; ok {
gt, tgr, err = fn(r)
} else {
gt, tgr, err = s.Server.ValidationTokenRequest(r)
}
if err != nil {
return
}
// ...
}