Skip to content

Commit

Permalink
Merge branch '114-authentication-should-return-username-in-token' int…
Browse files Browse the repository at this point in the history
…o 'main'

Resolve "Authentication should return username in token"

Closes #114

See merge request isard/isardvdi!328
  • Loading branch information
vittorio-togliatti committed Sep 8, 2021
2 parents 6d59d75 + de6ae94 commit 3fcb90e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## [3.1.1] - 2021-09-07

### Fixed

- Authentication user name in token and role in oauth

## [3.1.0] - 2021-09-01

### Added
Expand Down
6 changes: 6 additions & 0 deletions authentication/authentication/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type ClaimsData struct {
RoleID string `json:"role_id"`
CategoryID string `json:"category_id"`
GroupID string `json:"group_id"`
Name string `json:"name"`
}

func (a *Authentication) signToken(u *model.User) (string, error) {
Expand All @@ -102,6 +103,7 @@ func (a *Authentication) signToken(u *model.User) (string, error) {
u.Role,
u.Category,
u.Group,
u.Name,
},
})

Expand Down Expand Up @@ -265,6 +267,10 @@ func (a *Authentication) Callback(ctx context.Context, args map[string]string) (
}

if exists {
if err := u.Load(ctx, a.DB); err != nil {
return "", "", fmt.Errorf("load user from DB: %w", err)
}

ss, err = a.signToken(u)
if err != nil {
return "", "", err
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/NewNavBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

<!-- Right aligned nav items -->
<b-navbar-nav class="ml-auto">
<b-nav-item href="#"><span class="text-white">{{ getUser.username }} [{{ getUser.role_id }}]</span></b-nav-item>
<b-nav-item href="#"><span class="text-white">{{ getUser.name }} [{{ getUser.role_id }}]</span></b-nav-item>

<b-nav-item href="#" @click="logout()"
><b-icon
Expand Down
12 changes: 1 addition & 11 deletions frontend/src/store/modules/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,7 @@ import * as cookies from 'tiny-cookie'

export default {
state: {
user: {
UID: '',
Username: '',
Provider: '',
Category: '',
role: '',
group: '',
name: '',
email: '',
photo: ''
},
user: {},
token: '',
registerToken: '',
expirationDate: ''
Expand Down

0 comments on commit 3fcb90e

Please sign in to comment.