async def get(self, request): """Receive authorization token.""" url = str(request.url) if url[:5].lower() == "http:": url = f"https:{url[5:]}" if "code" not in url: return web_response.Response( headers={"content-type": "text/html"}, text="<script>window.close()</script>Error, the " "originating url does not seem to be a valid microsoft redirect", ) await self._hass.async_add_executor_job( ft.partial( self._account.con.request_token, url, state=self._state, redirect_uri=self._callback, )) account_data = self._hass.data[DOMAIN][self._account_name] do_setup(self._hass, self._config, self._account, self._account_name, self._conf_type) self.configurator.async_request_done(self._hass, account_data) self._log_authenticated() return web_response.Response( headers={"content-type": "text/html"}, text= "<script>window.close()</script>Success! This window can be closed", )
async def wrapped(request, **kwargs): """Notify that the API is running.""" hass = request.app["hass"] success = False if (request.remote not in cls.known_ips or (datetime.datetime.now() - cls.known_ips.get( request.remote)).seconds > cls.auth_seconds): try: flow_id = request.url.query["config_flow_id"] except KeyError as ex: raise Unauthorized() from ex for flow in hass.config_entries.flow.async_progress(): if flow["flow_id"] == flow_id: _LOGGER.debug( "Found flow_id; adding %s to known_ips for %s seconds", request.remote, cls.auth_seconds, ) success = True if not success: raise Unauthorized() cls.known_ips[request.remote] = datetime.datetime.now() try: return await cls.handler(request, **kwargs) except httpx.ConnectError as ex: # pylyint: disable=broad-except _LOGGER.warning("Detected Connection error: %s", ex) return web_response.Response( headers={"content-type": "text/html"}, text= f"Connection Error! Please try refreshing. If this persists, please report this error to <a href={ISSUE_URL}>here</a>:<br /><pre>{ex}</pre>", )
async def get(request): """Receive authorization code.""" from aiohttp import web_response if 'code' not in request.query or 'state' not in request.query: return web_response.Response( text="Missing code or state parameter in {}".format( request.url)) hass = request.app['hass'] hass.async_create_task( hass.config_entries.flow.async_configure( flow_id=request.query['state'], user_input=request.query['code'])) return web_response.Response(headers={'content-type': 'text/html'}, text="<script>window.close()</script>")
async def get(request): """Receive authorization code.""" from aiohttp import web_response if "code" not in request.query or "state" not in request.query: return web_response.Response( text="Missing code or state parameter in " + request.url) hass = request.app["hass"] hass.async_create_task( hass.config_entries.flow.async_configure( flow_id=request.query["state"], user_input=request.query["code"])) return web_response.Response( headers={"content-type": "text/html"}, text="<script>window.close()</script>", )
async def get(self, request): """Receive authorization confirmation.""" hass = request.app["hass"] await hass.config_entries.flow.async_configure( flow_id=request.query["flow_id"], user_input=None) return web_response.Response( headers={"content-type": "text/html"}, text= "<script>window.close()</script>Success! This window can be closed", )
async def get(self, request: web.Request): """Receive authorization confirmation.""" hass = request.app["hass"] try: await hass.config_entries.flow.async_configure( flow_id=request.query["flow_id"], user_input=None) except (KeyError, UnknownFlow) as ex: _LOGGER.debug("Callback flow_id is invalid.") raise HTTPBadRequest() from ex return web_response.Response( headers={"content-type": "text/html"}, text= "<script>window.close()</script>Success! This window can be closed", )
def get(self, request): from aiohttp import web_response """Receive authorization token.""" url = str(request.url) if url[:5].lower() == "http:": url = f"https:{url[5:]}" if "code" not in url: return web_response.Response( headers={"content-type": "text/html"}, text= "<script>window.close()</script>Error, the originating url does not seem to be a valid microsoft redirect", ) self.account.con.request_token(url, state=self.state, redirect_uri=self.callback) domain_data = self._hass.data[DOMAIN] do_setup(self._hass, self.config, self.account) self.configurator.async_request_done(domain_data) return web_response.Response( headers={"content-type": "text/html"}, text= "<script>window.close()</script>Success! This window can be closed", )