Example #1
0
 def __get_access_token(self) -> str:
     """
     Gets access token from self.token_data.access_token if not expired.
     If access_token is expired, refreshes and saves the new token data
     """
     if (self.jira.token_data.expiry_date is not None
             and self.jira.token_data.is_access_token_expired() is False):
         return self.jira.token_data.access_token
     else:
         logger.info(f"Token expired, refreshing... {self.team_id}")
         self.jira.token_data = JiraOauthService.refresh_access_token(
             self.jira.token_data)
         DynamoUtils.save_jira_data(self.team_id, self.jira)
         logger.info(f"Token refreshed and saved {self.team_id}")
         return self.jira.token_data.access_token
Example #2
0
def jira_oauth():
    """Endpoint to jira oauth flow"""
    code = request.args.get("code") or "no code!"
    state = request.args.get("state")
    decoded_state = base64.b64decode(state).decode()
    team_id, user_id = decoded_state.split(":")
    token_data: TokenData = JiraOauthService.get_token_data(code)
    try:
        account_id = JiraOauthService.get_jira_id(token_data.access_token)
        jira = Jira(token_data, account_id)
        DynamoUtils.save_jira_data(team_id, jira)
        return redirect(
            f"https://slack.com/app_redirect?app=A01H45TA509&team={team_id}",
            code=302)
    except Exception as e:
        logger.error(
            f"Could not authenticate jira app for team: {team_id} and user: {user_id} - {e}"
        )
        return ""