Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.

Commit e8c5e24

Browse files
committed
add user logout to openx
access token is invalidated by creating a new one, forcing other token requesting services to request a new token
1 parent 5182696 commit e8c5e24

File tree

4 files changed

+37
-34
lines changed

4 files changed

+37
-34
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM golang:alpine AS builder
22
RUN apk update && apk add --no-cache git ca-certificates && update-ca-certificates
33
WORKDIR $GOPATH/src/github.com/YaleOpenLab/openx
44
COPY . .
5-
RUN go mod download -x
5+
RUN go mod download
66
RUN go mod verify
77
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o openx
88
RUN ["cp", "dummyconfig.yaml", "config.yaml"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ The goal of openx is to have a common interface between all parties that relate
3535

3636
Openx builds are available at [builds.openx.solar](builds.openx.solar)
3737

38-
Docker image available [Docker Hub](https://hub.docker.com/repository/docker/varunramg/openx)
38+
Docker image available at [Docker Hub](https://hub.docker.com/repository/docker/varunramg/openx)
3939

4040
### Installing from PPA
4141

database/user.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,13 @@ func (a *User) GenAccessToken() (string, error) {
590590
return a.AccessToken, nil
591591
}
592592

593+
// AllLogout invalidates the user access token
594+
func (a *User) AllLogout() error {
595+
a.AccessToken = utils.GetRandomString(consts.AccessTokenLength)
596+
a.AccessTokenTimeout = utils.Unix()
597+
return a.Save()
598+
}
599+
593600
// AddtoMailbox adds a message to a user's mailbox
594601
func (a *User) AddtoMailbox(subject string, message string) error {
595602
var x MailboxHelper

rpc/users.go

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package rpc
22

33
import (
44
"encoding/hex"
5-
"encoding/json"
65
"io/ioutil"
76
"log"
87
"math"
@@ -39,7 +38,6 @@ var UserRPC = map[int][]string{
3938
11: []string{"/user/trustasset", "GET", "assetCode", "assetIssuer", "limit", "seedpwd"}, // GET
4039
12: []string{"/upload", "POST"}, // POST
4140
13: []string{"/platformemail", "GET"}, // GET
42-
16: []string{"/tellerping", "GET"}, // GET
4341
17: []string{"/user/increasetrustlimit", "GET", "trust", "seedpwd"}, // GET
4442
19: []string{"/user/sendrecovery", "GET", "email1", "email2", "email3"}, // GET
4543
20: []string{"/user/seedrecovery", "GET", "secret1", "secret2"}, // GET
@@ -60,11 +58,13 @@ var UserRPC = map[int][]string{
6058
36: []string{"/user/progress", "POST", "progress"}, // POST
6159
37: []string{"/user/update", "POST"}, // POST
6260
38: []string{"/user/tellerfile", "GET"}, // GET
61+
39: []string{"/user/logout", "POST"}, // POST
6362

6463
30: []string{"/user/anchorusd/kyc", "GET", "name", "bdaymonth", "bdayday", "bdayyear", "taxcountry", // GET
6564
"taxid", "addrstreet", "addrcity", "addrpostal", "addrregion", "addrcountry", "addrphone", "primaryphone", "gender"},
6665
// 14: []string{"/tellershutdown", "projIndex", "deviceId", "tx1", "tx2"},
6766
// 15: []string{"/tellerpayback", "deviceId", "projIndex"},
67+
// 16: []string{"/tellerping", "GET", "index"},
6868
// 18: []string{"/utils/addhash", "projIndex", "choice", "choicestr"},
6969
}
7070

@@ -84,11 +84,7 @@ func setupUserRpcs() {
8484
trustAsset()
8585
uploadFile()
8686
platformEmail()
87-
// sendTellerShutdownEmail()
88-
// sendTellerFailedPaybackEmail()
89-
tellerPing()
9087
increaseTrustLimit()
91-
// addContractHash()
9288
sendSecrets()
9389
mergeSecrets()
9490
generateNewSecrets()
@@ -109,6 +105,12 @@ func setupUserRpcs() {
109105
updateProgress()
110106
updateUser()
111107
downloadTeller()
108+
logout()
109+
110+
// sendTellerShutdownEmail()
111+
// sendTellerFailedPaybackEmail()
112+
// tellerPing()
113+
// addContractHash()
112114
}
113115

114116
const (
@@ -611,32 +613,6 @@ func platformEmail() {
611613
})
612614
}
613615

614-
// tellerPing pings the teller to check if its up
615-
func tellerPing() {
616-
http.HandleFunc(UserRPC[16][0], func(w http.ResponseWriter, r *http.Request) {
617-
_, err := userValidateHelper(w, r, UserRPC[16][2:], UserRPC[16][1])
618-
if err != nil {
619-
return
620-
}
621-
622-
data, err := erpc.GetRequest(TellerUrl + "/ping")
623-
if err != nil {
624-
erpc.ResponseHandler(w, erpc.StatusInternalServerError)
625-
return
626-
}
627-
628-
var x erpc.StatusResponse
629-
630-
err = json.Unmarshal(data, &x)
631-
if err != nil {
632-
erpc.ResponseHandler(w, erpc.StatusInternalServerError)
633-
return
634-
}
635-
636-
erpc.MarshalSend(w, x)
637-
})
638-
}
639-
640616
// increaseTrustLimit increases the trust limit a user has towards a specific asset on stellar
641617
func increaseTrustLimit() {
642618
http.HandleFunc(UserRPC[17][0], func(w http.ResponseWriter, r *http.Request) {
@@ -1415,3 +1391,23 @@ func downloadTeller() {
14151391
http.ServeFile(w, r, "screenlog.0")
14161392
})
14171393
}
1394+
1395+
// logout logs out from all devices
1396+
func logout() {
1397+
http.HandleFunc(UserRPC[39][0], func(w http.ResponseWriter, r *http.Request) {
1398+
//_, err := userValidateHelper(w, r, UserRPC[38][2:], UserRPC[38][1])
1399+
user, err := userValidateHelper(w, r, UserRPC[39][2:], UserRPC[39][1])
1400+
if err != nil {
1401+
return
1402+
}
1403+
1404+
err = user.AllLogout() // generate a new token to invalidate the old one
1405+
if err != nil {
1406+
log.Println(err)
1407+
erpc.ResponseHandler(w, erpc.StatusInternalServerError)
1408+
return
1409+
}
1410+
1411+
erpc.ResponseHandler(w, erpc.StatusOK)
1412+
})
1413+
}

0 commit comments

Comments
 (0)