diff --git a/go.mod b/go.mod index e7e86ba1e..349cf12fc 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/restic/calens v0.1.0 // indirect github.com/spf13/viper v1.5.0 github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce + github.com/yaegashi/msgraph.go v0.0.0-20191104022859-3f9096c750b2 go.opencensus.io v0.22.2 golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a diff --git a/go.sum b/go.sum index 219f709f7..5ac9baebf 100644 --- a/go.sum +++ b/go.sum @@ -673,6 +673,8 @@ github.com/xeipuuv/gojsonschema v1.1.0/go.mod h1:5yf86TLmAcydyeJq5YvxkGPE2fm/u4m github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca/go.mod h1:ce1O1j6UtZfjr22oyGxGLbauSBp2YVXpARAosm7dHBg= github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= +github.com/yaegashi/msgraph.go v0.0.0-20191104022859-3f9096c750b2 h1:37LbK2gAU+1oaWKC5NTz+fNOsR2LgdRj/SAFVMucgss= +github.com/yaegashi/msgraph.go v0.0.0-20191104022859-3f9096c750b2/go.mod h1:tso14hwzqX4VbnWTNsxiL0DvMb2OwbGISFA7jDibdWc= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.15.0/go.mod h1:UffZAU+4sDEINUGP/B7UfBBkq4fqLu9zXAX7ke6CHW0= diff --git a/pkg/server/http/server.go b/pkg/server/http/server.go index eae6b2c01..3b36ac9bc 100644 --- a/pkg/server/http/server.go +++ b/pkg/server/http/server.go @@ -1,6 +1,8 @@ package http import ( + "encoding/json" + "net/http" "time" "github.com/micro/go-micro/util/log" @@ -8,8 +10,34 @@ import ( "github.com/owncloud/ocis-graph/pkg/config" "github.com/owncloud/ocis-graph/pkg/flagset" "github.com/owncloud/ocis-graph/pkg/version" + msgraph "github.com/yaegashi/msgraph.go/v1.0" ) +func handleMe(writer http.ResponseWriter, req *http.Request) { + displayName := "Alice" + id := "1234-5678-9000-000" + me := &msgraph.User{ + DisplayName: &displayName, + GivenName: &displayName, + DirectoryObject: msgraph.DirectoryObject{ + Entity: msgraph.Entity{ + ID: &id, + }, + }, + } + + js, err := json.Marshal(me) + if err != nil { + //p.srv.Logger().Errorf("owncloud-plugin: error encoding response as json %s", err) + writer.WriteHeader(http.StatusInternalServerError) + return + } + + writer.Header().Set("Content-Type", "application/json") + writer.WriteHeader(http.StatusOK) + writer.Write(js) +} + func Server(opts ...Option) (web.Service, error) { options := newOptions(opts...) log.Infof("Server [http] listening on [%s]", options.Config.HTTP.Addr) @@ -35,5 +63,6 @@ func Server(opts ...Option) (web.Service, error) { ) service.Init() + service.HandleFunc("/v1.0/me", handleMe) return service, nil }