Skip to content

Commit

Permalink
fix logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain committed Jan 24, 2017
1 parent 2d347a2 commit aff1c19
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/apps/apps.go
Expand Up @@ -198,7 +198,7 @@ func (m *Manifest) BuildToken(i *instance.Instance) string {
IssuedAt: crypto.Timestamp(),
Subject: m.Slug,
},
Scope: "io.cozy._all", // TODO scope
Scope: "", // apps token doesnt have a scope
})
if err != nil {
return ""
Expand Down
2 changes: 1 addition & 1 deletion web/auth/auth.go
Expand Up @@ -117,7 +117,7 @@ func login(c echo.Context) error {

func logout(c echo.Context) error {
instance := middlewares.GetInstance(c)
claims, ok := c.Get("token_claims").(permissions.Claims)
claims, ok := c.Get("token_claims").(*permissions.Claims)
if !ok || claims.Audience != permissions.AppAudience {
return c.Redirect(http.StatusSeeOther, instance.SubDomain(apps.HomeSlug))
}
Expand Down
3 changes: 3 additions & 0 deletions web/auth/auth_test.go
Expand Up @@ -999,12 +999,15 @@ func TestLogoutNoToken(t *testing.T) {
func TestLogoutSuccess(t *testing.T) {
a := app.Manifest{Slug: "home"}
token := a.BuildToken(testInstance)
permissions.Create(testInstance, a.Slug, permissions.Set{})
req, _ := http.NewRequest("DELETE", ts.URL+"/auth/login", nil)
req.Host = domain
req.Header.Add("Authorization", "Bearer "+token)
res, err := client.Do(req)
assert.NoError(t, err)
defer res.Body.Close()
permissions.Destroy(testInstance, "home")

if assert.Equal(t, "303 See Other", res.Status) {
assert.Equal(t, "https://cozy.example.net/auth/login",
res.Header.Get("Location"))
Expand Down

0 comments on commit aff1c19

Please sign in to comment.