Store the token in local storage (#853)
Stores the token in local for any subsequent call to so the user doesn't need to sign in again after restarting their session
This commit is contained in:
parent
a8f4e4f0c2
commit
500a566abd
|
@ -84,6 +84,11 @@ export default class YammerProvider implements IYammerProvider {
|
|||
return new Promise((resolve, reject) => {
|
||||
window.yam.connect.loginButton(selector, (res: any) => {
|
||||
if (res.authResponse) {
|
||||
// Store the token in local storage for any subsequent call to Yammer
|
||||
// so the user doesn't need to sign in again after restarting their
|
||||
// browser session.
|
||||
localStorage.setItem("yammerAuthToken", res.access_token.token);
|
||||
|
||||
resolve(res);
|
||||
} else {
|
||||
reject(res);
|
||||
|
@ -92,6 +97,28 @@ export default class YammerProvider implements IYammerProvider {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Yammer JavaScript SDK "login" function wrapper.
|
||||
* See https://developer.yammer.com/docs/js-sdk.
|
||||
*/
|
||||
public login(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
window.yam.platform.login((res: any) => {
|
||||
if (res.authResponse) {
|
||||
// Store the token in local storage for any subsequent call to Yammer
|
||||
// so the user doesn't need to sign in again after restarting their
|
||||
// browser session.
|
||||
localStorage.setItem("yammerAuthToken", res.access_token.token);
|
||||
|
||||
resolve(res);
|
||||
}
|
||||
else {
|
||||
reject(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Yammer JavaScript SDK "request" function wrapper.
|
||||
* Public, but not recommended for extensive use.
|
||||
|
@ -135,6 +162,12 @@ export default class YammerProvider implements IYammerProvider {
|
|||
*/
|
||||
private _getLoginStatus(): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Apply the auth token we have stored in local storage
|
||||
let token = localStorage.getItem("yammerAuthToken");
|
||||
if (token) {
|
||||
window.yam.platform.setAuthToken(token);
|
||||
}
|
||||
|
||||
window.yam.getLoginStatus((res: any) => {
|
||||
if (res.authResponse) {
|
||||
resolve(res);
|
||||
|
|
Loading…
Reference in New Issue