File tree 2 files changed +23
-0
lines changed
2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -83,6 +83,21 @@ export class WSHeader extends Component {
83
83
this . authorization . unauthorize ( ) ;
84
84
}
85
85
86
+ /**
87
+ * Get abbreviation for the user the access token is issued for
88
+ * @returns {string|null }
89
+ */
90
+ static getUserAbbreviation ( ) {
91
+ try {
92
+ const json = JSON . parse ( atob ( this . getAccessToken ( ) ) ) ;
93
+ // Find key which contains the name
94
+ const nameKey = Object . keys ( json ) . find ( key => key . includes ( 'managed-id' ) ) ;
95
+ return json [ nameKey ] ;
96
+ } catch ( e ) {
97
+ return null ;
98
+ }
99
+ }
100
+
86
101
/**
87
102
* Retrieve the persisted locale
88
103
* @returns {string }
Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ describe('A WSHeader', () => {
31
31
expect ( WSHeader . getAccessToken ( ) ) . toBe ( tokenName ) ;
32
32
} ) ;
33
33
34
+ it ( 'get\'s the user abbreviation from access token' , ( ) => {
35
+ const tokenName = btoa ( '{"test": "asd", "asdasdmanaged-id": "supercooluser"}' ) ;
36
+ // Only test the basic function, the general authorization ist tested elsewhere
37
+ WSHeader . storage . set ( 'access_token' , tokenName ) ;
38
+ expect ( WSHeader . getUserAbbreviation ( ) ) . toBe ( 'supercooluser' ) ;
39
+ expect ( WSHeader . getAccessToken ( ) ) . toBe ( tokenName ) ;
40
+ } ) ;
41
+
34
42
it ( 'doesn\'t get an access token' , ( ) => {
35
43
const tokenName = 'asd' ;
36
44
// Only test the basic function, the general authorization ist tested elsewhere
You can’t perform that action at this time.
0 commit comments