Try using the following for the string template. I think the problem is how you use the <?!
syntax.
var template = "<b><a href='<?= getService().getAuthorizationUrl() ?>' target='_blank'>Click to Authorize</a></b><br/><? if (getService().hasAccess()) { ?> <p><span style='color:green'>Authorized Successfully</span></p> <? } else { ?> <p><span style='color:red'>Not Authorized</span></p> <? } ?>";
It's also a bit cleaner if you keep a separate HTML template file (I much prefer that, even for simple pages).
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<b>
<a href='<?= getService().getAuthorizationUrl() ?>' target='_blank'>Click to Authorize</a>
</b>
<br/>
<? if (getService().hasAccess()) { ?>
<p>
<span style='color:green'>Authorized Successfully</span>
</p>
<? } else { ?>
<p>
<span style='color:red'>Not Authorized</span>
</p>
<? } ?>
</body>
</html>