websocket and github user

18 views
Skip to first unread message

Anders Persson

unread,
Oct 14, 2018, 3:23:44 PM10/14/18
to Eiffel Web Framework
Hi

I am continuing with my work based on the websocket example. As authentication method I have used GitHub and when authenticated I can in the "execute" feature find the users name by calling:

request.execution_variable ("user")

but how do I get the user name when I am called by a websocket? For example in  "on_text" feature?

Anders

Anders Persson

unread,
Oct 17, 2018, 3:04:08 AM10/17/18
to Eiffel Web Framework
Hi

After some investigations I found that I can get it via the cookie that is set when authorizing the user 


 
if attached ws.request.cookie ({LOGIN_WITH_GITHUB_CONSTANTS}.oauth_user_login) as user then
 
Do something with user.string_representation
 
end


Anders

JV

unread,
Oct 27, 2018, 8:22:23 AM10/27/18
to eiffel-web...@googlegroups.com
Hi Anders, assuming you are doing something like this and you have access to the request: WSF_REQUEST from WEB_SOCKET


 
execute
       
local
            l_github_service
: LOGIN_WITH_GITHUB_SERVICE
            s
: STRING
       
do
            execute_oauth_session_filter


           
if request.has_execution_variable ("user") then
                   
-- Authenticated case
                   
                   
-- WebSocket URI /app  I'm assuming you want to have access to the web socket only for authenticated users.
                if request.path_info.same_string_general ("/app") then
                    s := websocket_app_html (request.server_name, request.server_port)
                       .....
                                end
                   
                    --URI logout
                if request.path_info.same_string_general ("/logout") then
                    handle_logout (request, response)
                end
               
                    -- Other Authenticated cases.
                   
            else
                    -- Not Authenticated case
     
            end
     end


execute_oauth_session_filter
                     
-- Filter the request to set the current user iff the oauth tokens exists.
       
do
           
if
                attached
{WSF_STRING} request.cookie (oauth_session_token) as l_roc_auth_session_token and then
                attached
{WSF_STRING} request.cookie (oauth_user_login) as l_user
           
then
                request
.set_execution_variable ("user", l_user.value)
             
end
         
end

 
   
You don't need to do

  if attached ws.request.cookie ({LOGIN_WITH_GITHUB_CONSTANTS}.oauth_user_login) as user then

       
-- Do something with user.string_representation
 
end


 
but quite similar, iff you have access to WSF_REQUEST from the WEB_SOCKET.

 if attached ws.request.execution_variable ("user") as l_user then
 
end



Finally, at the moment we don't have utility classes  like WEB_SOCKET_FILTER, WEB_SOCKET_FILTERED_ROUTED_EXECUTION
WEB_SOCKET_URI_HELPER_FOR_ROUTED_EXECUTION etc, adding this classes will make the web socket development easier. 
EiffelWeb project is a community project, and so if you want to contribute ;), I will help you with it.
Reply all
Reply to author
Forward
0 new messages