-
-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Oauth2.0 With AD Access ("Refresh Token") #4223
Comments
I suppose we're looking for a way to save the refresh token from the first auth response and then re-use it in subsequent requests that session. @VedoBlaze, please specify if necessary. @philippjfr, I see you are very active on this repo and was hoping you could help us resolve this. Is this something that could be supported in Panel? If it's not reasonable to build it into Panel, would it be possible to get some guidance on how to implement this in our setup? Thanks! |
Yes, I can investigate this. To be very clear under what conditions does this error occur exactly? On initial page load or are you trying to make requests to Azure APIs after the application is loaded? If you could provide as much detail as possible for me to reproduce this that would be great. |
I'll let VedoBlaze answer that, but here is some other information: the command we run panel with (on a Docker in AWS): |
@shkarlsson I've now made the You should then have access to |
I'll probably go ahead and merge it and cut a dev release you can test. |
I realize this is closed and maybe this needs a new issue, but: So in practice, #4227 doesn't really solve the problem unless there's a way to update the cookie through the websocket. (Which I believe there isn't?) |
Thanks @xnsde. Would love to chat to figure out what exactly is needed here. Based on those docs my understanding was that in general a refresh token is valid for 24 hours, and didn't see any reference to them being single-use. |
Hi @xnsde Since you can use Panel to execute javascript scripts, I believe you can update secure cookies through the web socket. There are many ways to invoke javascript scripts. For awesome-panel.org/sharing I needed optional (github) oauth for public apps. I could not see how to use Panels built in OAuth to support this use case. So I built my own Github OAuth component inspired by Panels OAuth and using ReactiveHTML. You can find the full import panel as pn
import param
class JSActions(pn.reactive.ReactiveHTML): # pylint: disable=too-many-ancestors
"""Helper class for triggering js functions"""
_set_cookie = param.Dict()
_delete_secure_cookie = param.String()
_template = """<div id="jsaction" style="height:0px;width:0px"></div>"""
_scripts = {
"_set_cookie": """
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/;secure";
}
const {name, value, days}=data._set_cookie
createCookie(name, value, days)""",
"_delete_secure_cookie": """
value=data._delete_secure_cookie+'=; Max-Age=-99999999; path=/;secure'
document.cookie = value
""",
}
def __init__(self):
super().__init__(height=0, width=0, sizing_mode="fixed", margin=0)
def set_secure_cookie(self, name, value, days=1.0):
"""Sets a cookie as a secure cookie
Args:
name: The name of the cookie
value: The value of the cookie. Please note you will have to encrypt this your self
days: Days to expiration. Defaults to 1.0.
"""
self._set_cookie = {"name": name, "value": value, "days": days}
def delete_secure_cookie(self, name):
"""Deletes the cookie
Args:
name: The name of the cookie to delete
"""
self._delete_secure_cookie = name |
Oh, seems you're actually right as far as Azure is concerned: |
Hmm.. Just to give some context:
The reactivehtml solution does seem to mostly solve it. |
Hi,
We are using this custom plugin but are getting a issue when calling the Azure platform 2.0 OAuth.
The issue we are getting is
"ERROR: panel.auth - AzureAd OAuth provider returned a HTTP 400: Bad Request error. The full response was: {'error': 'invalid_grant', 'error_description': 'AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token.\r\nTrace ID: ff5daa04-a393-4bfc-9cfd-1ae511fb3e00\r\nCorrelation ID: e78f94a1-90d9-41d5-a7a1-221238ffa5b2\r\nTimestamp: 2022-11-29 14:30:03Z', 'error_codes': [54005], 'timestamp': '2022-11-29 14:30:03Z', 'trace_id': 'ff5daa04-a393-4bfc-9cfd-1ae511fb3e00', 'correlation_id': 'e78f94a1-90d9-41d5-a7a1-221238ffa5b2'}"
Through some error searching we have navigated that the solution is in enabling a way in getting refresh tokens. LInk below:
https://learn.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow#refresh-the-access-token
Is hit something you can implement so that we can further use panel?
Thanks in advance for you contribution.
The text was updated successfully, but these errors were encountered: