Fix person reauth (#13839)

* add null checks
* fix/improve account.html

Signed-off-by: Tom Deckers <tom@ducbase.com>
This commit is contained in:
Tom Deckers
2022-12-04 19:16:07 +01:00
committed by GitHub
parent 741f7decac
commit 45a3054c76
3 changed files with 12 additions and 8 deletions

View File

@@ -121,7 +121,7 @@ public class WebexAuthServlet extends HttpServlet {
replaceMap.put(KEY_PAGE_REFRESH, replaceMap.put(KEY_PAGE_REFRESH,
params.isEmpty() ? "" : String.format(HTML_META_REFRESH_CONTENT, servletBaseURL)); params.isEmpty() ? "" : String.format(HTML_META_REFRESH_CONTENT, servletBaseURL));
if (!reqError.isBlank()) { if (reqError != null && !reqError.isBlank()) {
logger.debug("Webex redirected with an error: {}", reqError); logger.debug("Webex redirected with an error: {}", reqError);
replaceMap.put(KEY_ERROR, String.format(HTML_ERROR, reqError)); replaceMap.put(KEY_ERROR, String.format(HTML_ERROR, reqError));
} else if (!reqState.isBlank()) { } else if (!reqState.isBlank()) {
@@ -172,12 +172,12 @@ public class WebexAuthServlet extends HttpServlet {
map.put(ACCOUNT_SHWOMSG, "u-show"); map.put(ACCOUNT_SHWOMSG, "u-show");
map.put(ACCOUNT_MSG, "Configure account."); map.put(ACCOUNT_MSG, "Configure account.");
} else if (handler.isAuthorized()) { } else if (handler.isAuthorized()) {
map.put(ACCOUNT_USER_ID, String.format(" (Authorized user: %s)", webexUser)); map.put(ACCOUNT_USER_ID, String.format("Authorized user: %s", webexUser));
map.put(ACCOUNT_SHOWBTN, "u-hide"); map.put(ACCOUNT_SHOWBTN, "u-hide");
map.put(ACCOUNT_SHWOMSG, "u-show"); map.put(ACCOUNT_SHWOMSG, "u-show");
map.put(ACCOUNT_MSG, "Authorized."); map.put(ACCOUNT_MSG, "Authorized.");
} else if (!webexUser.isBlank()) { } else if (webexUser.isBlank()) {
map.put(ACCOUNT_USER_ID, String.format(" (Unauthorized user: %s)", webexUser)); map.put(ACCOUNT_USER_ID, "Unauthorized user");
map.put(ACCOUNT_SHOWBTN, "u-show"); map.put(ACCOUNT_SHOWBTN, "u-show");
map.put(ACCOUNT_SHWOMSG, "u-hide"); map.put(ACCOUNT_SHWOMSG, "u-hide");
map.put(ACCOUNT_MSG, ""); map.put(ACCOUNT_MSG, "");

View File

@@ -70,7 +70,7 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
private @Nullable OAuthClientService authService; private @Nullable OAuthClientService authService;
private boolean configured = false; // is the handler instance properly configured? private boolean configured; // is the handler instance properly configured?
private volatile boolean active; // is the handler instance active? private volatile boolean active; // is the handler instance active?
String accountType = ""; // bot or person? String accountType = ""; // bot or person?
@@ -97,6 +97,7 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
public void initialize() { public void initialize() {
logger.debug("Initializing thing {}", this.getThing().getUID()); logger.debug("Initializing thing {}", this.getThing().getUID());
active = true; active = true;
this.configured = false;
config = getConfigAs(WebexTeamsConfiguration.class); config = getConfigAs(WebexTeamsConfiguration.class);
final String token = config.token; final String token = config.token;
@@ -210,6 +211,9 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
public boolean isAuthorized() { public boolean isAuthorized() {
final AccessTokenResponse accessTokenResponse = getAccessTokenResponse(); final AccessTokenResponse accessTokenResponse = getAccessTokenResponse();
if (accessTokenResponse == null) {
return false;
}
if ("person".equals(this.accountType)) { if ("person".equals(this.accountType)) {
return accessTokenResponse != null && accessTokenResponse.getAccessToken() != null return accessTokenResponse != null && accessTokenResponse.getAccessToken() != null
@@ -287,7 +291,7 @@ public class WebexTeamsHandler extends BaseThingHandler implements AccessTokenRe
updateStatus(ThingStatus.ONLINE); updateStatus(ThingStatus.ONLINE);
return true; return true;
} catch (WebexTeamsException e) { } catch (WebexTeamsException e) {
logger.warn("Failed to refresh: {}", e.getMessage()); logger.warn("Failed to refresh: {}. Did you authorize?", e.getMessage());
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
} }
return false; return false;

View File

@@ -1,6 +1,6 @@
<div class="row" id="${account.id}"> <div class="row" id="${account.id}">
<div class="one column">${account.type}:</div> <div class="three columns">${account.name}:</div>
<div class="nine columns"><i>${account.name}${account.user}</i></div> <div class="seven columns"><i>${account.user} (${account.type})</i></div>
<div class="two columns ${account.showbtn}"> <div class="two columns ${account.showbtn}">
<div class="button-primary"><a href=${account.authorize}>Authorize Account</a></div> <div class="button-primary"><a href=${account.authorize}>Authorize Account</a></div>
</div> </div>