-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ResponseModeHandler to support custom response modes (#592)
Closes #591
- Loading branch information
Showing
9 changed files
with
159 additions
and
32 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
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,47 @@ | ||
package fosite | ||
|
||
import "net/http" | ||
|
||
// ResponseModeHandler provides a contract for handling custom response modes | ||
type ResponseModeHandler interface { | ||
// ResponseModes returns a set of supported response modes handled | ||
// by the interface implementation. | ||
// | ||
// In an authorize request with any of the provide response modes | ||
// methods `WriteAuthorizeResponse` and `WriteAuthorizeError` will be | ||
// invoked to write the successful or error authorization responses respectively. | ||
ResponseModes() ResponseModeTypes | ||
|
||
// WriteAuthorizeResponse writes successful responses | ||
// | ||
// Following headers are expected to be set by default: | ||
// header.Set("Cache-Control", "no-store") | ||
// header.Set("Pragma", "no-cache") | ||
WriteAuthorizeResponse(rw http.ResponseWriter, ar AuthorizeRequester, resp AuthorizeResponder) | ||
|
||
// WriteAuthorizeError writes error responses | ||
// | ||
// Following headers are expected to be set by default: | ||
// header.Set("Cache-Control", "no-store") | ||
// header.Set("Pragma", "no-cache") | ||
WriteAuthorizeError(rw http.ResponseWriter, ar AuthorizeRequester, err error) | ||
} | ||
|
||
type ResponseModeTypes []ResponseModeType | ||
|
||
func (rs ResponseModeTypes) Has(item ResponseModeType) bool { | ||
for _, r := range rs { | ||
if r == item { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
type DefaultResponseModeHandler struct{} | ||
|
||
func (d *DefaultResponseModeHandler) ResponseModes() ResponseModeTypes { return nil } | ||
func (d *DefaultResponseModeHandler) WriteAuthorizeResponse(rw http.ResponseWriter, ar AuthorizeRequester, resp AuthorizeResponder) { | ||
} | ||
func (d *DefaultResponseModeHandler) WriteAuthorizeError(rw http.ResponseWriter, ar AuthorizeRequester, err error) { | ||
} |