mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 20:49:16 +00:00
adding auth claim to test setup
This commit is contained in:
parent
5fb8c5f245
commit
f447dd1195
@ -1,20 +1,33 @@
|
|||||||
/*
|
|
||||||
* DataBag
|
|
||||||
*
|
|
||||||
* DataBag provides storage for decentralized identity based self-hosting apps. It is intended to support sharing of personal data and hosting group conversations.
|
|
||||||
*
|
|
||||||
* API version: 0.0.1
|
|
||||||
* Contact: roland.osborne@gmail.com
|
|
||||||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
|
||||||
*/
|
|
||||||
package databag
|
package databag
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Authorize(w http.ResponseWriter, r *http.Request) {
|
func Authorize(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
account, code, res := BearerAppToken(r, true);
|
||||||
|
if res != nil {
|
||||||
|
ErrResponse(w, code, res)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
detail := account.AccountDetail
|
||||||
|
|
||||||
|
var token string
|
||||||
|
if err := ParseRequest(r, w, &token); err != nil {
|
||||||
|
ErrResponse(w, http.StatusBadRequest, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
claim := &Claim{ Token: token }
|
||||||
|
|
||||||
|
msg, err := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType,
|
||||||
|
APP_SIGNPKCS1V15, account.Guid, APP_MSGAUTHENTICATE, &claim)
|
||||||
|
if err != nil {
|
||||||
|
ErrResponse(w, http.StatusInternalServerError, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteResponse(w, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,6 +519,8 @@ func AddTestAccount(username string) (guid string, token string, err error) {
|
|||||||
Description: "A test app",
|
Description: "A test app",
|
||||||
Url: "http://app.example.com",
|
Url: "http://app.example.com",
|
||||||
};
|
};
|
||||||
|
var claim Claim
|
||||||
|
var msg DataMessage
|
||||||
var profile Profile
|
var profile Profile
|
||||||
var login = username + ":pass"
|
var login = username + ":pass"
|
||||||
|
|
||||||
@ -564,6 +566,21 @@ func AddTestAccount(username string) (guid string, token string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
token = guid + "." + access
|
token = guid + "." + access
|
||||||
|
|
||||||
|
// authorize claim
|
||||||
|
if r, w, err = NewRequest("PUT", "/authorize", "1234abcd"); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
SetBearerAuth(r, token)
|
||||||
|
Authorize(w, r)
|
||||||
|
if err = ReadResponse(w, &msg); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
signer, messageType, _, res := ReadDataMessage(&msg, &claim)
|
||||||
|
if res != nil || signer != guid || messageType != APP_MSGAUTHENTICATE || claim.Token != "1234abcd" {
|
||||||
|
err = errors.New("invalid authenticated claim")
|
||||||
|
return
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user