Skip to content

Commit

Permalink
fix links
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptix committed Mar 25, 2021
1 parent 991a9d8 commit c624dc5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 21 deletions.
2 changes: 1 addition & 1 deletion web/handlers/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (a aliasHandler) resolve(rw http.ResponseWriter, req *http.Request) {

alias, err := a.db.Resolve(req.Context(), name)
if err != nil {
ar.SendError(err)
ar.SendError(fmt.Errorf("aliases: failed to resolve name %q: %w", name, err))
return
}

Expand Down
16 changes: 11 additions & 5 deletions web/handlers/auth/withssb.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"io"
"net/http"
"net/url"
"strings"
"time"

kitlog "github.com/go-kit/kit/log"
Expand Down Expand Up @@ -107,10 +108,11 @@ func (h WithSSBHandler) login(w http.ResponseWriter, req *http.Request) (interfa
// check that we have that member
member, err := h.membersdb.GetByFeed(req.Context(), client)
if err != nil {
errMsg := fmt.Errorf("sign-in with ssb: client isnt a member: %w", err)
if err == roomdb.ErrNotFound {
return nil, weberrors.ErrForbidden{Details: fmt.Errorf("sign-in: client isnt a member")}
return nil, weberrors.ErrForbidden{Details: errMsg}
}
return nil, err
return nil, errMsg
}
clientReq.ClientID = client

Expand All @@ -131,13 +133,14 @@ func (h WithSSBHandler) login(w http.ResponseWriter, req *http.Request) (interfa
var solution string
err = edp.Async(ctx, &solution, muxrpc.TypeString, muxrpc.Method{"httpAuth", "requestSolution"}, sc, cc)
if err != nil {
return nil, err
return nil, fmt.Errorf("sign-in with ssb: could not request solution from client: %w", err)
}

// decode and validate the response
solutionBytes, err := base64.URLEncoding.DecodeString(solution)
solution = strings.TrimSuffix(solution, ".sig.ed25519")
solutionBytes, err := base64.StdEncoding.DecodeString(solution)
if err != nil {
return nil, err
return nil, fmt.Errorf("sign-in with ssb: failed to decode solution: %w", err)
}

if !clientReq.Validate(solutionBytes) {
Expand All @@ -147,17 +150,20 @@ func (h WithSSBHandler) login(w http.ResponseWriter, req *http.Request) (interfa
// create a session for invalidation
tok, err := h.sessiondb.CreateToken(req.Context(), member.ID)
if err != nil {
err = fmt.Errorf("sign-in with ssb: could not create token: %w", err)
return nil, err
}

session, err := h.cookieStore.Get(req, siwssbSessionName)
if err != nil {
err = fmt.Errorf("sign-in with ssb: failed to load cookie session: %w", err)
return nil, err
}

session.Values[memberToken] = tok
session.Values[userTimeout] = time.Now().Add(lifetime)
if err := session.Save(req, w); err != nil {
err = fmt.Errorf("sign-in with ssb: failed to update cookie session: %w", err)
return nil, err
}

Expand Down
14 changes: 7 additions & 7 deletions web/router/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ const (
AuthFallbackSignInForm = "auth:fallback:signin:form"
AuthFallbackSignIn = "auth:fallback:signin"

AuthWithSSBSignIn = "auth:ssb:signin"
AuthWithSSBSignIn = "auth:ssb:login"
// AuthWithSSBSignIn

AuthSignOut = "auth:logout"
)

// NewSignin constructs a mux.Router containing the routes for sign-in and -out
// Auth constructs a mux.Router containing the routes for sign-in and -out
func Auth(m *mux.Router) *mux.Router {
if m == nil {
m = mux.NewRouter()
}

// register fallback
m.Path("/fallback/signin").Methods("GET").Name(AuthFallbackSignInForm)
m.Path("/fallback/signin").Methods("POST").Name(AuthFallbackSignIn)

m.Path("/withssb/signin").Methods("GET").Name(AuthWithSSBSignIn)
// register password fallback
m.Path("/password/signin").Methods("GET").Name(AuthFallbackSignInForm)
m.Path("/password/signin").Methods("POST").Name(AuthFallbackSignIn)

m.Path("/login").Methods("GET").Name(AuthWithSSBSignIn)
m.Path("/logout").Methods("GET").Name(AuthSignOut)

return m
Expand Down
4 changes: 2 additions & 2 deletions web/router/complete.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ const (
func CompleteApp() *mux.Router {
m := mux.NewRouter()

Auth(m.PathPrefix("/auth").Subrouter())
Auth(m)
Admin(m.PathPrefix("/admin").Subrouter())

m.Path("/").Methods("GET").Name(CompleteIndex)
m.Path("/about").Methods("GET").Name(CompleteAbout)

m.Path("/{alias}").Methods("GET").Name(CompleteAliasResolve)
m.Path("/alias/{alias}").Methods("GET").Name(CompleteAliasResolve)

m.Path("/invite/accept").Methods("GET").Name(CompleteInviteAccept)
m.Path("/invite/consume").Methods("POST").Name(CompleteInviteConsume)
Expand Down
4 changes: 2 additions & 2 deletions web/templates/admin/members-remove-confirm.tmpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{ define "title" }}{{i18n "AdminAllowListRemoveConfirmTitle"}}{{ end }}
{{ define "title" }}{{i18n "AdminMembersRemoveConfirmTitle"}}{{ end }}
{{ define "content" }}
<div class="flex flex-col justify-center items-center h-64">

<span
id="welcome"
class="text-center"
>{{i18n "AdminAllowListRemoveConfirmWelcome"}}</span>
>{{i18n "AdminMembersRemoveConfirmWelcome"}}</span>

<pre
id="verify"
Expand Down
5 changes: 1 addition & 4 deletions web/templates/auth/withssb_sign_in.tmpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{{ define "title" }}{{i18n "AuthWithSSBTitle"}}{{ end }}
{{ define "content" }}
<div id="page-header">
<h1 id="welcome" class="text-lg">{{i18n "AuthWithSSBWelcome"}}</h1>
</div>
<div>
<pre>{{.}}</pre>
<a href="{{urlTo "admin:dashboard"}}">Proceed to Dashboard</a>
</div>
{{end}}

0 comments on commit c624dc5

Please sign in to comment.