PySide6.QtNetworkAuth.QOAuthHttpServerReplyHandler¶
- class QOAuthHttpServerReplyHandler¶
- Handles loopback redirects by setting up a local HTTP server. More… - Synopsis¶- Methods¶- def - __init__()
- def - callbackPath()
- def - callbackText()
- def - close()
- def - isListening()
- def - listen()
- def - port()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors. - This class serves as a reply handler for OAuth 2.0 authorization processes that use loopback redirection . - The redirect URI is where the authorization server redirects the user-agent (typically, and preferably, the system browser) once the authorization part of the flow is complete. Loopback redirect URIs use - httpas the scheme and either localhost or an IP address literal as the host (see- IPv4 and IPv6).- QOAuthHttpServerReplyHandlersets up a localhost server. Once the authorization server redirects the browser to this localhost address, the reply handler parses the redirection URI query parameters, and then signals authorization completion with- a signal.- To handle other redirect URI schemes, see - QOAuthUriSchemeReplyHandler.- The following code illustrates the usage. First, the needed variables: - m_oauth = QOAuth2AuthorizationCodeFlow() m_handler = None - Followed up by the OAuth setup (error handling omitted for brevity): - m_oauth.setAuthorizationUrl(QUrl("https://some.authorization.service/v3/authorize")) m_oauth.setAccessTokenUrl(QUrl("https://some.authorization.service/v3/access_token")) m_oauth.setClientIdentifier("a_client_id") m_oauth.setScope("read") m_handler = QOAuthHttpServerReplyHandler(1234, self) m_oauth.authorizeWithBrowser.connect(self.openUrl) m_oauth.granted.connect(this, [this]() { # Here we use QNetworkRequestFactory to store the access token m_api.setBearerToken(m_oauth.token().toLatin1()) m_handler.close() }) - Finally, we then set up the URI scheme reply-handler: - m_oauth.setReplyHandler(m_handler) # Initiate the authorization if m_handler.isListening(): m_oauth.grant() - IPv4 and IPv6¶- If the handler is an any address handler (AnyIPv4, AnyIPv6, or Any), the used callback is in the form of - http://localhost:{port}/{path}. Handler will first attempt to listen on IPv4 loopback address, and then on IPv6.- localhostis used because it resolves correctly on both IPv4 and IPv6 interfaces.- For loopback addresses (LocalHost or LocalHostIPv6) the IP literals ( - 127.0.0.1and- ::1) are used.- For specific IP addresses the provided IP literal is used directly, for instance: http://192.168.0.123:{port}/{path} in the case of an IPv4 address. - Constructs a - QOAuthHttpServerReplyHandlerobject using- parentas a parent object. Calls- listen()with port- 0and address LocalHost.- See also - __init__(port[, parent=None])
- Parameters:
- port – int 
- parent – - QObject
 
 
 - Constructs a - QOAuthHttpServerReplyHandlerobject using- parentas a parent object. Calls- listen()with- portand address LocalHost.- See also - __init__(address, port[, parent=None])
- Parameters:
- address – - QHostAddress
- port – int 
- parent – - QObject
 
 
 - Constructs a - QOAuthHttpServerReplyHandlerobject using- parentas a parent object. Calls- listen()with- addressand- port.- See also - callbackPath()¶
- Return type:
- str 
 
 - Returns the path that is used as the path component of the - callback()/ OAuth2 redirect_uri parameter .- See also - callbackText()¶
- Return type:
- str 
 
 - Returns the text that is used in response to the redirection at the end of the authorization stage. - The text is wrapped in a simple HTML page, and displayed to the user by the browser / user-agent which did the redirection. - The default text is - Callback received. Feel free to close this page. - See also - close()¶
 - Tells this handler to stop listening for connections / redirections. - See also - isListening()¶
- Return type:
- bool 
 
 - Returns - trueif this handler is currently listening, and- falseotherwise.- listen([address=QHostAddress.Any[, port=0]])¶
- Parameters:
- address – - QHostAddress
- port – int 
 
- Return type:
- bool 
 
 - Tells this handler to listen for incoming connections / redirections on - addressand- port. Returns- trueif listening is successful, and- falseotherwise.- Active listening is only required when performing the initial authorization phase, typically initiated by a - grant()call.- It is recommended to close the listener after successful authorization. Listening is not needed for - requesting access tokensor refreshing them.- If this function is called with Null as the - address, the handler will attempt to listen to LocalHost, and if that fails, LocalHostIPv6.- See also - IPv4 and IPv6.- See also - port()¶
- Return type:
- int 
 
 - Returns the port on which this handler is listening, otherwise returns 0. - See also - setCallbackPath(path)¶
- Parameters:
- path – str 
 
 - Sets - pathto be used as the path component of the- callback().- See also - setCallbackText(text)¶
- Parameters:
- text – str 
 
 - Sets - textto be used in response to the redirection at the end of the authorization stage.- See also