mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
moving profile to token based auth
This commit is contained in:
parent
d6dff01317
commit
3c3771ece4
66
doc/api.oa3
66
doc/api.oa3
@ -464,29 +464,6 @@ paths:
|
|||||||
'500':
|
'500':
|
||||||
description: internal server error
|
description: internal server error
|
||||||
|
|
||||||
/account/profile/image:
|
|
||||||
get:
|
|
||||||
tags:
|
|
||||||
- account
|
|
||||||
description: Get profile image. Access granted to account's username and password
|
|
||||||
operationId: get-account-image
|
|
||||||
security:
|
|
||||||
- basicAuth: []
|
|
||||||
responses:
|
|
||||||
'200':
|
|
||||||
description: success
|
|
||||||
content:
|
|
||||||
application/octet-stream: # content specific
|
|
||||||
schema:
|
|
||||||
type: string
|
|
||||||
format: binary
|
|
||||||
'401':
|
|
||||||
description: permission denied
|
|
||||||
'405':
|
|
||||||
description: invalid image
|
|
||||||
'500':
|
|
||||||
description: internal server error
|
|
||||||
|
|
||||||
/account/assets/{assetId}:
|
/account/assets/{assetId}:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
@ -700,8 +677,13 @@ paths:
|
|||||||
- profile
|
- profile
|
||||||
description: Get profile of accunt. Access granted to app token of account holder.
|
description: Get profile of accunt. Access granted to app token of account holder.
|
||||||
operationId: get-profile
|
operationId: get-profile
|
||||||
security:
|
parameters:
|
||||||
- bearerAuth: []
|
- name: agent
|
||||||
|
in: query
|
||||||
|
description: agent token
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: success
|
description: success
|
||||||
@ -722,8 +704,13 @@ paths:
|
|||||||
- profile
|
- profile
|
||||||
description: Set profile data. Access granted to app tokens of account holder.
|
description: Set profile data. Access granted to app tokens of account holder.
|
||||||
operationId: set-profile
|
operationId: set-profile
|
||||||
security:
|
parameters:
|
||||||
- bearerAuth: []
|
- name: agent
|
||||||
|
in: query
|
||||||
|
description: agent token
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: success
|
description: success
|
||||||
@ -777,8 +764,13 @@ paths:
|
|||||||
- profile
|
- profile
|
||||||
description: Set base64 encode image data for profile. Access granted to app tokens of account holder.
|
description: Set base64 encode image data for profile. Access granted to app tokens of account holder.
|
||||||
operationId: set-profile-image
|
operationId: set-profile-image
|
||||||
security:
|
parameters:
|
||||||
- bearerAuth: []
|
- name: agent
|
||||||
|
in: query
|
||||||
|
description: agent token
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: success
|
description: success
|
||||||
@ -806,15 +798,19 @@ paths:
|
|||||||
- profile
|
- profile
|
||||||
description: Get a profile data message. Access granted to app token of account holder or contact token of connected contact.
|
description: Get a profile data message. Access granted to app token of account holder or contact token of connected contact.
|
||||||
operationId: get-profile-message
|
operationId: get-profile-message
|
||||||
security:
|
|
||||||
- bearerAuth: []
|
|
||||||
parameters:
|
parameters:
|
||||||
- in: header
|
- name: agent
|
||||||
name: TokenType
|
in: query
|
||||||
|
description: agent token
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
- name: contact
|
||||||
|
in: query
|
||||||
|
description: contact token
|
||||||
|
required: false
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
enum: [ app, contact ]
|
|
||||||
required: true
|
|
||||||
responses:
|
responses:
|
||||||
'200':
|
'200':
|
||||||
description: success
|
description: success
|
||||||
|
@ -6,8 +6,9 @@ import (
|
|||||||
|
|
||||||
func GetProfile(w http.ResponseWriter, r *http.Request) {
|
func GetProfile(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
account, code, err := BearerAppToken(r, true);
|
account, code, err := ParamAgentToken(r, true);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
PrintMsg(r);
|
||||||
ErrResponse(w, code, err)
|
ErrResponse(w, code, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package databag
|
|||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strings"
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -849,22 +850,42 @@ func TestApiRequest(endpoint func(http.ResponseWriter, *http.Request), params *T
|
|||||||
if rest == "" {
|
if rest == "" {
|
||||||
rest = "GET"
|
rest = "GET"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if params.tokenType == APP_TOKENAPP {
|
||||||
|
if !strings.Contains(params.query, "?") {
|
||||||
|
params.query += "?"
|
||||||
|
} else {
|
||||||
|
params.query += "&"
|
||||||
|
}
|
||||||
|
params.query += "agent=" + params.token
|
||||||
|
} else if params.tokenType == APP_TOKENCONTACT {
|
||||||
|
if !strings.Contains(params.query, "?") {
|
||||||
|
params.query += "?"
|
||||||
|
} else {
|
||||||
|
params.query += "&"
|
||||||
|
}
|
||||||
|
params.query += "contact=" + params.token
|
||||||
|
}
|
||||||
|
|
||||||
if r, w, err = NewRequest(rest, params.query, params.body); err != nil {
|
if r, w, err = NewRequest(rest, params.query, params.body); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
r = mux.SetURLVars(r, params.path)
|
r = mux.SetURLVars(r, params.path)
|
||||||
|
|
||||||
if params.tokenType != "" {
|
if params.tokenType != "" {
|
||||||
r.Header.Add("TokenType", params.tokenType)
|
r.Header.Add("TokenType", params.tokenType)
|
||||||
}
|
}
|
||||||
if params.token != "" {
|
if params.token != "" {
|
||||||
SetBearerAuth(r, params.token)
|
SetBearerAuth(r, params.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.authorization != "" {
|
if params.authorization != "" {
|
||||||
SetBasicAuth(r, params.authorization)
|
SetBasicAuth(r, params.authorization)
|
||||||
}
|
}
|
||||||
if params.credentials != "" {
|
if params.credentials != "" {
|
||||||
SetCredentials(r, params.credentials)
|
SetCredentials(r, params.credentials)
|
||||||
}
|
}
|
||||||
|
|
||||||
endpoint(w, r)
|
endpoint(w, r)
|
||||||
|
|
||||||
res := w.Result()
|
res := w.Result()
|
||||||
|
@ -111,6 +111,22 @@ func ApiTestMsg(
|
|||||||
var r *http.Request
|
var r *http.Request
|
||||||
var w *httptest.ResponseRecorder
|
var w *httptest.ResponseRecorder
|
||||||
|
|
||||||
|
if tokenType == APP_TOKENAPP {
|
||||||
|
if !strings.Contains(name, "?") {
|
||||||
|
name += "?"
|
||||||
|
} else {
|
||||||
|
name += "&"
|
||||||
|
}
|
||||||
|
name += "agent=" + token
|
||||||
|
} else if tokenType == APP_TOKENCONTACT {
|
||||||
|
if !strings.Contains(name, "?") {
|
||||||
|
name += "?"
|
||||||
|
} else {
|
||||||
|
name += "&"
|
||||||
|
}
|
||||||
|
name += "contact=" + token
|
||||||
|
}
|
||||||
|
|
||||||
if r, w, err = NewRequest(requestType, name, body); err != nil {
|
if r, w, err = NewRequest(requestType, name, body); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user