confluence-go-api icon indicating copy to clipboard operation
confluence-go-api copied to clipboard

api.User(username) panics with invalid memory address error

Open shansara-ghub opened this issue 3 years ago • 4 comments

The api.User() panics with the invalid memory address error. It looks like the cause of the error stems from the getUserEndpoint() as it returns the path as "/rest/api/user/" where as it should return the path as "/rest/api/user?" ?

Because according to the https://developer.atlassian.com/cloud/confluence/rest/api-group-users/#api-api-user-get, see the '?' in the url

curl --request GET \
  --url 'https://your-domain.atlassian.net/wiki/rest/api/user?accountId={accountId}' \
  --header 'Accept: application/json'

the below works perfectly ok. curl -v -k -X GET 'https://confluence.go.com/rest/api/user?username={gouser}' -H "Authorization: OAuth gousertoken"

{ "type": "known", "username": "GoUser", "userKey": "40282be65460e1310154be02974f2376", "profilePicture": { "path": "/images/icons/profilepics/default.svg", "width": 48, "height": 48, "isDefault": true }, "displayName": "Go Confluence User", "_links": { "base": "https://confluence.go.com", "context": "", "self": "https://confluence.go.com/rest/api/user?key=40282be65460e1310154be02974f2376" } }

Expected behavior The api.User() should ok.

Release version 1.3.2

Additional context The code that produces the error is below for your reference - main.go.txt

Any help is appreciated.

shansara-ghub avatar Jun 22 '21 15:06 shansara-ghub

hi @shansara-ghub thanks for your issue. I changed this in branch issue-32. Can you test if the fix works for you?

Btw your main.go example references a fork not the original repo.

c-seeger avatar Jun 22 '21 16:06 c-seeger

Hi @c-seeger - I see when the username and the token are not blank, the authentication being performed is "Basic"

func (r *Request) SetBasicAuth(username, password string) { r.Header.Set("Authorization", "Basic "+basicAuth(username, password)) } func (a *API) Auth(req *http.Request) { //Supports unauthenticated access to confluence: //if username and token are not set, do not add authorization header if a.username != "" && a.token != "" { req.SetBasicAuth(a.username, a.token) } } So the token based auth (OAuth) is not supported ?

shansara-ghub avatar Jun 22 '21 23:06 shansara-ghub

@shansara-ghub no OAuth is not implemented yet. I'll open another issue for this as a feature request.

c-seeger avatar Jun 24 '21 07:06 c-seeger

@shansara-ghub can you confirm if the fix works now with basic auth?

c-seeger avatar Jun 26 '21 08:06 c-seeger