OfficeDev / office-js-helpers

[ARCHIVED] A collection of helpers to simplify development of Office Add-ins & Microsoft Teams Tabs
MIT License
126 stars 56 forks source link

token expires check is not correct #80

Open sremiger1 opened 6 years ago

sremiger1 commented 6 years ago

https://github.com/OfficeDev/office-js-helpers/blob/master/src/authentication/token.manager.ts

method hasExpired

Line

if (token.expires_at == null) {
      return false;
    }

It is not correct if the token has an expires_at and it is null than the token has not expired but if the token exists but the expire_at is undefined than the token is not correctly formed for this eval

If the token does not have an

access_token

then the token no matter what is not valid.

I am stuck in a loop because if this.

if ( !authenticationService.hasToken() ) {
        authenticationService.login().then(() => {
            location.reload();
        }, renderRejected );
    }
    else {
        renderMessage();
    }
public hasToken(): boolean {

        if (this.token != null && this.token.access_token != undefined) {
            return true;
        }

        return false;
    }
 public async login(): Promise<OfficeHelpers.IToken> {
        try {
            console.log('Login');
            this.token = await this.authenticator.authenticate(configEndPointName, false);
            debugger;
            return this.token;
        }
        catch (err) {
            let errorList: TWErrorList = this.buildErrorList(err, { 'key': 'Authentication Error', 'value': 'Failed to authenticate', level: 0 } );
            throw errorList;
        }
    }

This worked in release.0.7.4 but does not work in 1.0.0 0.7.4 returned a null and 1.0.0 returns a token

It also seems you can get into an infinite loop The get calls the delete the delete calls the get

image 3

WrathOfZombies commented 6 years ago

Good catch. Sorry for the regression. I'll look into it.