How to implement login/logout in the Facebook through desktop application

You have to take a web browser (e.g. The DJ project), which will be inserted into your desktop application.

Navigate to
https://graph.facebook.com/oauth/authorize
?client_id={client_id}
&redirect_uri=http://www.facebook.com/connect/login_success.html
&type=user_agent&scope={permissions}

and the login form will appear.
You need to input an email and password, and to press Login.

After this user will be redirected to the redirect_uri, which will contain access_token
http://www.facebook.com/connect/login_success.html
#access_token=161713100507627|2.R8bXAgr9wdiQYWJgVx_yPg__.3600.1301475600-100001169602345|sY-fl-62kCSgcn1pgiv2fYsltHE
&expires_in=5996

(note: use WebBrowserListener to parse the token and for other actions)

Now you can get some info, e.g. about current user (use any http-request)
https://graph.facebook.com/me?access_token={access_token}
(server returns JSON)

User will be logged in until the application is running or until cookies exist (if user have selected ‘Keep me logged in’) or expires_in has not ended.
(Note: this browser uses IE cookie for Windows OS)

Thus we should log out from Facebook.
Navigate to
http://m.facebook.com/logout.php?confirm=1&next={other_url}
and user will be deauthorized (cookeis removed)

More info read on Facebook Authentication