Skip to content

Commit

Permalink
Specify the type of authorization info
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed Jan 23, 2018
1 parent 2bb4673 commit 3553eba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
11 changes: 3 additions & 8 deletions plugin/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@ func (a *auth) Name() string {
}

func (a *auth) PostDial(sess tp.EarlySession) *tp.Rerror {
rerr := sess.Send(authURI, a.generateAuthInfoFunc(), nil)
rerr := sess.Send(authURI, a.generateAuthInfoFunc(), nil, socket.WithBodyCodec('s'))
if rerr != nil {
return rerr
}

_, rerr = sess.Receive(func(header socket.Header) interface{} {
return nil
})

return nil
return rerr
}

func (a *auth) PostAccept(sess tp.EarlySession) *tp.Rerror {
Expand All @@ -83,14 +81,11 @@ func (a *auth) PostAccept(sess tp.EarlySession) *tp.Rerror {
if rerr != nil {
return rerr
}

if input.Uri() != authURI {
return tp.NewRerror(tp.CodeBadPacket, tp.CodeText(tp.CodeBadPacket), "Received an unexecepted response: "+input.Uri())
return tp.NewRerror(tp.CodeBadPacket, tp.CodeText(tp.CodeBadPacket), "received an unexecepted response: "+input.Uri())
}

authInfo := *input.Body().(*string)
rerr = a.verifyAuthInfoFunc(authInfo, sess)

rerr2 := sess.Send(authURI, nil, rerr)
if rerr == nil {
rerr = rerr2
Expand Down
8 changes: 4 additions & 4 deletions samples/auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
func main() {
cli := tp.NewPeer(tp.PeerConfig{}, plugin.LaunchAuth(generateAuthInfo))
defer cli.Close()
_, e := cli.Dial(":9090")
if e != nil {
tp.Fatalf("%v", e)
_, rerr := cli.Dial(":9090")
if rerr != nil {
tp.Fatalf("%v", rerr)
}
}

const clientAuthInfo = "client auth info"
const clientAuthInfo = "client-auth-info-12345"

func generateAuthInfo() string {
tp.Infof("generate auth info: %s", clientAuthInfo)
Expand Down
2 changes: 1 addition & 1 deletion samples/auth/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func main() {
}

const (
clientAuthInfo = "client auth info"
clientAuthInfo = "client-auth-info-12345"
codeAuthFail = 403
textAuthFail = "auth fail"
detailAuthFail = "auth fail detail"
Expand Down

0 comments on commit 3553eba

Please sign in to comment.