Skip to content

Commit

Permalink
Merge pull request #30 from themue/master
Browse files Browse the repository at this point in the history
Fixed renamed function AddTokenToRequest()
  • Loading branch information
Frank Mueller authored Oct 25, 2017
2 parents 96ccf1a + 6e52260 commit bcd39d5
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 40 deletions.
77 changes: 42 additions & 35 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,74 +1,81 @@
# Tideland Go REST Server Library

## 2017-10-25

- Function `jwt.AddTokenToRequest()` is deprecated, now it
is `AddToRequest()`; sadly forgot backward compatability,
so now are both available but first with an according
comment

## 2017-09-10

- Fixed return code in case of not implemented HTTP methods
to *405* (method not allowed)
to `405` (method not allowed)

## 2017-06-19

- Reduced job handling complexity

## 2017-05-15

- Changed *Job.Path()* to return a *Path* instance
- Changed `Job.Path()` to return a `Path` instance
- This instance provides access to the different parts
of the path
- Now *JoinedResourceID()* has the role of the former
*ResourceID()* (*Job* uses this one in the deprecated
*ResourceID()*) while the method *ResourceID()* of path
- Now `JoinedResourceID()` has the role of the former
`ResourceID()` (`Job` uses this one in the deprecated
`ResourceID()`) while the method `ResourceID()` of path
returns only the third part of the path

## 2017-04-26

- Added access to URL path parts via *Job.Path()*
- Added access to URL path parts via `Job.Path()`
- Added interfaces for handler methods directly mapping
HTTP verbs to the according REST methods like *Create()*,
*Read()*, *Update()*, *Modify()*, *Delete()*, and *Info()*
HTTP verbs to the according REST methods like `Create()`,
`Read()`, `Update()`, `Modify()`, `Delete()`, and `Info()`

## 2017-03-20

- Rename internal *envelope* to public *Feedback* in *rest*
- Added *ReadFeedback()* to *Response* in *request*
- Asserts in *restaudit* now internally increase the callstack
- Rename internal `envelope` to public `Feedback` in `rest`
- Added `ReadFeedback()` to `Response` in `request`
- Asserts in `restaudit` now internally increase the callstack
offset so that the correct test line number is shown
- Added *Response.AssertBodyGrep()* to *restaudit*
- Added `Response.AssertBodyGrep()` to `restaudit`

## 2017-02-12

- Some renamings in *Request* and *Response*, sadly
- Some renamings in `Request` and `Response`, sadly
incompatible to the previous minor release
- More convenience helpers for testing
- Adopted new testing to more packages
- Using http package constants instead of own
plain strings
- Added documentation to *restaudit*
- Added documentation to `restaudit`

## 2017-02-10

- Extended *Request* and *Response* of *restaudit* with some
- Extended `Request` and `Response` of `restaudit` with some
convenience methods for easier testing
- Adopted *restaudit* changes in *rest* tests
- Adopted `restaudit` changes in `rest` tests

## 2017-01-19

- Renamed type *Query* to *Values*
- Added *Form()* to *Job*
- Renamed type `Query` to `Values`
- Added `Form()` to `Job`

## 2016-12-15

- Added *StatusCode* to feedback envelope
- *JWTAuthorizationHandler* now provides different status codes
- Added `StatusCode` to feedback envelope
- `JWTAuthorizationHandler` now provides different status codes
depending on valid tokens, expiration time, and authorization

## 2016-12-09

- *FileServeHandler* now logs the absolute filename and logs
- `FileServeHandler` now logs the absolute filename and logs
error if the name is invalid

## 2016-12-06

- *PositiveFeedback()* and *NegativeFeedback()* now also return
- `PositiveFeedback()` and `NegativeFeedback()` now also return
false to be directly used as final return in handler methods

## 2016-12-02
Expand All @@ -81,20 +88,20 @@

## 2016-11-23

- Added *JWTFromContext()* to *handlers*
- Later removed JWT context from *handler*; now *jwt* package
has *NewContext()* and *FromContext()* as usual
- Added `JWTFromContext()` to `handlers`
- Later removed JWT context from `handler`; now `jwt` package
has `NewContext()` and `FromContext()` as usual

## 2016-11-07

- Added *RegisteredHandlers()* to *Multiplexer* retrieve the list
- Added `RegisteredHandlers()` to `Multiplexer` retrieve the list
of registered handlers for one domain and resource
- *Deregister()* is now more flexible in deristering multiple
- `Deregister()` is now more flexible in deristering multiple
or all handlers for one domain and resource at once

## 2016-11-03

- Added *request* package for more convenient requests to REST APIs
- Added `request` package for more convenient requests to REST APIs

## 2016-10-25

Expand All @@ -106,25 +113,25 @@

## 2016-10-18

- Added *Query* type and method for more concenient access to
- Added `Query` type and method for more concenient access to
query values

## 2016-10-08

- *Job* allows now to enhance its context for following handlers
- *JWTAuthorizationHandler* stores a successfully checked token
- `Job` allows now to enhance its context for following handlers
- `JWTAuthorizationHandler` stores a successfully checked token
in the job context

## 2016-10-05

- *Formatter.Write()* now also writes the status code
- `Formatter.Write()` now also writes the status code

## 2016-10-04

- Improved passing external contexts into an environment, e.g.
containing database connection pools
- Changed multiplexer configuration to now use *etc.Etc* from
the *Tideland Go Library*
- Changed multiplexer configuration to now use `etc.Etc` from
the `Tideland Go Library`
- More robust basepath handling now

## 2016-09-29
Expand All @@ -142,5 +149,5 @@

## 2016-08-21

- Migrated *Tideland Go Library* web package after some rework
- Migrated `Tideland Go Library` web package after some rework
into this new project
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ I hope you like it. ;)

## Version

Version 2.15.2
Version 2.15.4

## Packages

Expand Down
2 changes: 1 addition & 1 deletion handlers/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func TestJWTAuthorizationHandler(t *testing.T) {
req := restaudit.NewRequest("GET", "/jwt/"+test.id+"/1234567890")
if test.tokener != nil {
req.SetRequestProcessor(func(req *http.Request) *http.Request {
return jwt.AddTokenToRequest(req, test.tokener())
return jwt.AddToRequest(req, test.tokener())
})
}
// Make request(s).
Expand Down
2 changes: 1 addition & 1 deletion handlers/jwtauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (h *jwtAuthorizationHandler) check(job rest.Job) (bool, error) {
}
// Now do the checks.
if err != nil {
return h.deny(job, rest.StatusBadRequest, err.Error())
return h.deny(job, rest.StatusUnauthorized, err.Error())
}
if token == nil {
return h.deny(job, rest.StatusUnauthorized, "no JSON Web Token")
Expand Down
11 changes: 10 additions & 1 deletion jwt/header.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Tideland Go REST Server Library - JSON Web Token - Header
//
// Copyright (C) 2016 Frank Mueller / Tideland / Oldenburg / Germany
// Copyright (C) 2016-2017 Frank Mueller / Tideland / Oldenburg / Germany
//
// All rights reserved. Use of this source code is governed
// by the new BSD license.
Expand All @@ -16,13 +16,22 @@ import (
"strings"

"github.com/tideland/golib/errors"

"github.com/tideland/gorest/rest"
)

//--------------------
// REQUEST AND JOB HANDLING
//--------------------

// AddTokenToRequest adds a token as header to a request for
// usage by a client.
//
// DEPRECATED: Now AddToRequest().
func AddTokenToRequest(req *http.Request, jwt JWT) *http.Request {
return AddToRequest(req, jwt)
}

// AddToRequest adds a token as header to a request for
// usage by a client.
func AddToRequest(req *http.Request, jwt JWT) *http.Request {
Expand Down
2 changes: 1 addition & 1 deletion request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (c *caller) prepareRequest(method, urlStr string, params *Parameters) (*htt
request.Header.Set("Version", params.Version.String())
}
if params.Token != nil {
request = jwt.AddTokenToRequest(request, params.Token)
request = jwt.AddToRequest(request, params.Token)
}
if params.Accept == "" {
params.Accept = params.ContentType
Expand Down

0 comments on commit bcd39d5

Please sign in to comment.