Use access token rather than id token when calling API
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
|||||||
getUserInfo,
|
getUserInfo,
|
||||||
clear,
|
clear,
|
||||||
getExpiresAt,
|
getExpiresAt,
|
||||||
|
getAccessToken,
|
||||||
} from './storage';
|
} from './storage';
|
||||||
|
|
||||||
export default class AuthenticationClient {
|
export default class AuthenticationClient {
|
||||||
@@ -113,4 +114,8 @@ export default class AuthenticationClient {
|
|||||||
idToken() {
|
idToken() {
|
||||||
return getIdToken();
|
return getIdToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
accessToken() {
|
||||||
|
return getAccessToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,4 +43,5 @@ export const clearStateAndNonce = () => {
|
|||||||
|
|
||||||
export const getUserInfo = () => JSON.parse(localStorage.getItem(STORAGE_USER));
|
export const getUserInfo = () => JSON.parse(localStorage.getItem(STORAGE_USER));
|
||||||
export const getIdToken = () => localStorage.getItem(STORAGE_ID);
|
export const getIdToken = () => localStorage.getItem(STORAGE_ID);
|
||||||
|
export const getAccessToken = () => localStorage.getItem(STORAGE_ACCESS);
|
||||||
export const getExpiresAt = () => JSON.parse(localStorage.getItem(STORAGE_EXPIRES));
|
export const getExpiresAt = () => JSON.parse(localStorage.getItem(STORAGE_EXPIRES));
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ const auth0Config = {
|
|||||||
redirectUri: getRedirectUri(),
|
redirectUri: getRedirectUri(),
|
||||||
audience: "http://dancefinder.unbound.se",
|
audience: "http://dancefinder.unbound.se",
|
||||||
responseType: "token id_token",
|
responseType: "token id_token",
|
||||||
scope: "openid profile readwrite:settings"
|
scope: "openid profile email readwrite:settings"
|
||||||
};
|
};
|
||||||
|
|
||||||
const webAuth = new AuthClient(auth0Config);
|
const webAuth = new AuthClient(auth0Config);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const webAuth = require("../auth").default;
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
includeCredentials: (uri, options) => {
|
includeCredentials: (uri, options) => {
|
||||||
const token = webAuth.idToken();
|
const token = webAuth.accessToken();
|
||||||
if (token) {
|
if (token) {
|
||||||
options.headers['Authorization'] = 'Bearer ' + token;
|
options.headers['Authorization'] = 'Bearer ' + token;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user