mirror of
https://github.com/thomiceli/opengist.git
synced 2024-12-23 13:02:39 +00:00
19 lines
446 B
Go
19 lines
446 B
Go
|
package auth
|
||
|
|
||
|
type AuthInfoProvider interface {
|
||
|
RequireLogin() (bool, error)
|
||
|
AllowGistsWithoutLogin() (bool, error)
|
||
|
}
|
||
|
|
||
|
func ShouldAllowUnauthenticatedGistAccess(prov AuthInfoProvider, isSingleGistAccess bool) (bool, error) {
|
||
|
require, err := prov.RequireLogin()
|
||
|
if err != nil {
|
||
|
return false, err
|
||
|
}
|
||
|
allow, err := prov.AllowGistsWithoutLogin()
|
||
|
if err != nil {
|
||
|
return false, err
|
||
|
}
|
||
|
return !require || (isSingleGistAccess && allow), nil
|
||
|
}
|