How can I get current user in RPC call?

#1

Hello.

I can’t find out how can I authenticate use in RPC call. Registration, login and session is handled with Django. I have add dynamic authentication for connection to server:

def authenticate(realm, authid, details):

print(“authenticate called: realm = ‘{}’, authid = ‘{}’”.format(realm, authid))

cookie = cookies.SimpleCookie()

cookie.load(details[‘transport’][‘http_headers_received’].get(‘cookie’, ‘’))

session_cookie = cookie.get(settings.SESSION_COOKIE_NAME)

if session_cookie is None:

raise ApplicationError(ApplicationError.AUTHORIZATION_FAILED)

session = SessionStore(session_cookie.value)

request = RequestMock()

request.session = session

user = get_user(request)

if user.is_authenticated():

return {

‘authid’: user.username,

‘secret’: ‘user’,

‘role’: ‘user’

}

else:

raise ApplicationError(

ApplicationError.AUTHORIZATION_FAILED,

“could not authenticate session - no such user {}”.format(authid))

It works great (I know that Django is not asynchronous, but it does not matter for one request).

And now it is nor clear how can I get current user in RPC function. I do not want to send some key with every request and handle some session in global object for this key, because it is ugly.

0 Likes

#2

You will need to add { disclose_me: true } to the options of .call. When you do that, session.authid will be populated.

Regards,

Andrew Eddie

···

On Saturday, 15 August 2015 21:49:03 UTC+10, Dmitriy Kostochko wrote:

And now it is nor clear how can I get current user in RPC function.

0 Likes