add comment id to rss

This commit is contained in:
Umputun
2019-01-08 03:59:15 -06:00
parent 781d90e98b
commit 61cf54d231
13 changed files with 40 additions and 43 deletions
+3 -4
View File
@@ -112,19 +112,18 @@
version = "v1.0.0"
[[projects]]
digest = "1:5371050ba40cd7482fa2e9f0ff17fc18e2c37a6353ac012eaaacc6250eee4748"
digest = "1:94bd00c67ee734ccdafa8c29a3dec31a71e1c0906d12136d50b59af98f0f2a9c"
name = "github.com/go-pkgz/auth"
packages = [
".",
"avatar",
"logger",
"middleware",
"provider",
"token",
]
pruneopts = "UT"
revision = "6f889bf1c6eb61c926dbb759897e6dc577b10655"
version = "v0.3.0"
revision = "720bf3c94e674562c17355923524c067e43b6078"
version = "v0.3.1"
[[projects]]
digest = "1:01f2a0dea4785957fb0832580a244e693c710130e2785e4a2f73cc7872cdfa82"
+1
View File
@@ -164,6 +164,7 @@ func (s *Rest) toRssFeed(url string, comments []store.Comment) (string, error) {
Description: c.Text,
Created: c.Timestamp,
Author: &feeds.Author{Name: c.User.Name},
Id: c.ID,
}
if c.ParentID != "" {
// add indication to parent comment
+2 -1
View File
@@ -203,7 +203,8 @@ _Warning: this is not the real oauth2 server but just a small fake thing for dev
In addition to the primary method (i.e. JWT cookie with XSRF header) there are two more ways to authenticate:
1. Send JWT header as `X-JWT`. This shouldn't be used for web application, however can be helpful for service-to-service authentication.
2. [Basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). This mode disabled by default and will be enabled if `Opts.AdminPasswd` defined. This will allow access with basic auth admin:<Opts.AdminPasswd> with user [admin](https://github.com/go-pkgz/auth/blob/master/middleware/auth.go#L24). Such method can be used for automation scripts.
2. Send JWT token as query parameter, i.e. `/something?token=<jwt>`
3. [Basic access authentication](https://en.wikipedia.org/wiki/Basic_access_authentication). This mode disabled by default and will be enabled if `Opts.AdminPasswd` defined. This will allow access with basic auth admin:<Opts.AdminPasswd> with user [admin](https://github.com/go-pkgz/auth/blob/master/middleware/auth.go#L24). Such method can be used for automation scripts.
### Logging
+4 -4
View File
@@ -6,11 +6,11 @@ import (
"strings"
"time"
"github.com/go-pkgz/lgr"
"github.com/go-pkgz/rest"
"github.com/pkg/errors"
"github.com/go-pkgz/auth/avatar"
"github.com/go-pkgz/auth/logger"
"github.com/go-pkgz/auth/middleware"
"github.com/go-pkgz/auth/provider"
"github.com/go-pkgz/auth/token"
@@ -18,7 +18,7 @@ import (
// Service provides higher level wrapper allowing to construct everything and get back token middleware
type Service struct {
logger logger.L
logger lgr.L
opts Opts
jwtService *token.Service
providers []provider.Service
@@ -56,7 +56,7 @@ type Opts struct {
AdminPasswd string // if presented, allows basic auth with user admin and given password
AudienceReader token.Audience // list of allowed aud values, default (empty) allows any
RefreshFactor int // estimated number of request client sends in parallel during token refresh.
Logger logger.L // logger interface, default is no logging at all
Logger lgr.L // logger interface, default is no logging at all
}
// NewService initializes everything
@@ -78,7 +78,7 @@ func NewService(opts Opts) (res *Service) {
}
if opts.Logger == nil {
res.logger = logger.Func(func(fmt string, args ...interface{}) {}) // do-nothing logger
res.logger = lgr.Func(func(fmt string, args ...interface{}) {}) // do-nothing logger
}
jwtService := token.NewService(token.Opts{
+2 -2
View File
@@ -12,18 +12,18 @@ import (
"strings"
"time"
"github.com/go-pkgz/lgr"
"github.com/go-pkgz/rest"
"github.com/pkg/errors"
"golang.org/x/image/draw"
"github.com/go-pkgz/auth/logger"
"github.com/go-pkgz/auth/token"
)
// Proxy provides http handler for avatars from avatar.Store
// On user login token will call Put and it will retrieve and save picture locally.
type Proxy struct {
logger.L
lgr.L
Store Store
RoutePath string
URL string
+2
View File
@@ -5,10 +5,12 @@ require (
github.com/coreos/bbolt v1.3.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
github.com/go-pkgz/lgr v0.1.0 // indirect
github.com/go-pkgz/mongo v1.0.0
github.com/go-pkgz/rest v1.1.5
github.com/nullrocks/identicon v0.0.0-20180626043057-7875f45b0022
github.com/pkg/errors v0.8.0
github.com/stretchr/objx v0.1.1 // indirect
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 // indirect
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890
+8
View File
@@ -2,12 +2,17 @@ cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/coreos/bbolt v1.3.0 h1:HIgH5xUWXT914HCI671AxuTTqjj64UOFr7pHn48LUTI=
github.com/coreos/bbolt v1.3.0/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 h1:DujepqpGd1hyOd7aW59XpK7Qymp8iy83xq74fLr21is=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-pkgz/lgr v0.0.0-20190107224007-7d791fb529cb h1:HBzmL2t7mb8A14Vc1uMInWQlKAY5rq1i1M4svUIQTNQ=
github.com/go-pkgz/lgr v0.0.0-20190107224007-7d791fb529cb/go.mod h1:hBM1NM/SoYdlrykgdgJWGrZ/TM/XaZIjRbJfx7NkMm8=
github.com/go-pkgz/lgr v0.1.0 h1:JzSBxyNW9gli9PMVGI8IUhmFsQZaK2usJ62pmUGj0BY=
github.com/go-pkgz/lgr v0.1.0/go.mod h1:hBM1NM/SoYdlrykgdgJWGrZ/TM/XaZIjRbJfx7NkMm8=
github.com/go-pkgz/mongo v1.0.0 h1:9jijAK7prCRMetiyTu3c1rv/2lMypzuf2DWcVpTlwzw=
github.com/go-pkgz/mongo v1.0.0/go.mod h1:R9si/F2aJsjz4MUxhzuppIHY8yLV3YCeuCpgcI50cu4=
github.com/go-pkgz/rest v1.1.3 h1:rMf+xJn8i1Ip9OKohusZsRxwntM0BwYu8OX8BuEwN80=
@@ -24,8 +29,11 @@ github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b h1:VHyIDlv3XkfCa5/a81uzaoDkHH4rr81Z62g+xlnO8uM=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3 h1:eH6Eip3UpmR+yM/qI9Ijluzb1bNv/cAU/n+6l8tRSis=
-20
View File
@@ -1,20 +0,0 @@
package logger
import "log"
// L defines minimal interface used to log things
type L interface {
Logf(format string, args ...interface{})
}
// Func type is an adapter to allow the use of ordinary functions as Logger.
type Func func(format string, args ...interface{})
// Logf calls f(id)
func (f Func) Logf(format string, args ...interface{}) { f(format, args...) }
// NoOp logger
var NoOp = Func(func(format string, args ...interface{}) {})
// Std logger
var Std = Func(func(format string, args ...interface{}) { log.Printf(format, args...) })
+2 -2
View File
@@ -5,16 +5,16 @@ import (
"math/rand"
"net/http"
"github.com/go-pkgz/lgr"
"github.com/pkg/errors"
"github.com/go-pkgz/auth/logger"
"github.com/go-pkgz/auth/provider"
"github.com/go-pkgz/auth/token"
)
// Authenticator is top level auth object providing middlewares
type Authenticator struct {
logger.L
lgr.L
JWTService TokenService
Providers []provider.Service
Validator token.Validator
+2 -2
View File
@@ -10,11 +10,11 @@ import (
"text/template"
"time"
"github.com/go-pkgz/lgr"
"github.com/nullrocks/identicon"
"github.com/pkg/errors"
"golang.org/x/oauth2"
"github.com/go-pkgz/auth/logger"
"github.com/go-pkgz/auth/token"
)
@@ -26,7 +26,7 @@ const devAuthPort = 8084
// can run in interactive and non-interactive mode. In interactive mode login attempts will show login form to select
// desired user name, this is the mode used for development. Non-interactive mode for tests only.
type DevAuthServer struct {
logger.L
lgr.L
Provider Oauth2Handler
Automatic bool
username string // unsafe, but fine for dev
+3 -3
View File
@@ -4,17 +4,17 @@ import (
"errors"
"net/http"
"github.com/dgrijalva/jwt-go"
jwt "github.com/dgrijalva/jwt-go"
"github.com/go-pkgz/lgr"
"github.com/go-pkgz/rest"
"github.com/go-pkgz/auth/logger"
"github.com/go-pkgz/auth/token"
)
// DirectHandler implements non-oauth2 provider authorizing user in traditional way with storage
// with users and hashes
type DirectHandler struct {
logger.L
lgr.L
CredChecker CredChecker
ProviderName string
TokenService TokenService
+3 -3
View File
@@ -9,10 +9,10 @@ import (
"time"
jwt "github.com/dgrijalva/jwt-go"
"github.com/go-pkgz/lgr"
"github.com/go-pkgz/rest"
"golang.org/x/oauth2"
"github.com/go-pkgz/auth/logger"
"github.com/go-pkgz/auth/token"
)
@@ -32,7 +32,7 @@ type Oauth2Handler struct {
// Params to make initialized and ready to use provider
type Params struct {
logger.L
lgr.L
URL string
JwtService TokenService
Cid string
@@ -54,7 +54,7 @@ func (u userData) value(key string) string {
// initOauth2Handler makes oauth2 handler for given provider
func initOauth2Handler(p Params, service Oauth2Handler) Oauth2Handler {
if p.L == nil {
p.L = logger.Func(func(fmt string, args ...interface{}) {})
p.L = lgr.NoOp
}
p.Logf("[INFO] init oauth2 service %s", service.name)
service.Params = p
+8 -2
View File
@@ -38,6 +38,7 @@ const (
jwtHeaderKey = "X-JWT"
xsrfCookieName = "XSRF-TOKEN"
xsrfHeaderKey = "X-XSRF-TOKEN"
tokenQuery = "token"
issuer = "go-pkgz/auth"
tokenDuration = time.Minute * 15
cookieDuration = time.Hour * 24 * 31
@@ -208,15 +209,20 @@ func (j *Service) Set(w http.ResponseWriter, claims Claims) error {
return nil
}
// Get token from header or cookie
// Get token from url, header or cookie
// if cookie used, verify xsrf token to match
func (j *Service) Get(r *http.Request) (Claims, string, error) {
fromCookie := false
tokenString := ""
// try to get from "token" query param
if tkQuery := r.URL.Query().Get(tokenQuery); tkQuery != "" {
tokenString = tkQuery
}
// try to get from X-JWT header
if tokenHeader := r.Header.Get(jwtHeaderKey); tokenHeader != "" {
if tokenHeader := r.Header.Get(jwtHeaderKey); tokenHeader != "" && tokenString == "" {
tokenString = tokenHeader
}