Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a lot of things about sharing #1130

Merged
merged 12 commits into from
Jan 2, 2018
Prev Previous commit
Next Next commit
Fix the request to accept a sharing
  • Loading branch information
nono committed Dec 27, 2017
commit 8e8cb0d68b702ce7e62e0e7c91f5cfac4ef8e54d
9 changes: 7 additions & 2 deletions pkg/sharings/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sharings
import (
"encoding/json"
"fmt"
"net/http"
"net/url"

"github.com/cozy/cozy-stack/client/auth"
Expand Down Expand Up @@ -94,9 +95,13 @@ func RegisterClientOnTheRecipient(i *instance.Instance, s *Sharing, m *Member, u
// AcceptSharingRequest is called on the recipient when the permissions for the
// sharing are accepted. It calls the cozy of the owner to start the sharing,
// and then create the sharing (and other stuff) in its couchdb.
func AcceptSharingRequest(i *instance.Instance, answerURL, scope string) error {
func AcceptSharingRequest(i *instance.Instance, answerURL *url.URL, scope string) error {
res, err := request.Req(&request.Options{
Addr: answerURL,
Method: http.MethodPost,
Scheme: answerURL.Scheme,
Domain: answerURL.Host,
Path: answerURL.Path,
Queries: answerURL.Query(),
Headers: request.Headers{"Accept": "application/json"},
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion web/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ func authorize(c echo.Context) error {
u.Fragment = ""

if params.resType == consts.SharingResponseType {
if err = sharings.AcceptSharingRequest(instance, u.String(), params.scope); err != nil {
if err = sharings.AcceptSharingRequest(instance, u, params.scope); err != nil {
instance.Logger().Warnf("[sharing] Error on accepting a sharing: %s", err)
// It is safer to delete the client, as it may have a token and
// this cozy has no document to acknowledge that
Expand Down