Skip to content

allow browser-based logins for clients - #24835

Closed
ChristophWurst wants to merge 5 commits into
masterfrom
browser-based-client-login
Closed

ChristophWurst wants to merge 5 commits into
masterfrom
browser-based-client-login

Conversation

@ChristophWurst

@ChristophWurst ChristophWurst commented May 25, 2016 •

Copy link
Copy Markdown
Contributor

TODO

  • create DB table to store temporary access tokens
  • finish implementation
  • allow password-less login (we may need a new token type for that)
  • tests
  • extract login name and password from session token and save it to access token. Save those credentials with the new device token then.

OPTIONAL

fixes #24794

@mention-bot

Copy link
Copy Markdown

By analyzing the blame information on this pull request, we identified @tanghus, @LukasReschke and @bartv2 to be potential reviewers

@ChristophWurst

Copy link
Copy Markdown
Contributor Author

Simple tests

Testing with curl:

$ curl --request POST localhost:8080/index.php/auth/start | python -m json.tool                                                                                             
{                                                                                                                                                                                                                         
    "url": "http://localhost:8080/index.php/auth/check?accesstoken=9VeXzLiLWWGdd/hmSWq8hQezOC4LviawdT1gj%2Bb7JbqmFiphcT5orxak4WOi5jh%2BDqLppUcojcfHlPGZ508KtoHGabtgDmG8qWsTJyWWyMx4JtSiYOFup%2BPQxvoAc5FO",               
    "accessToken": "9VeXzLiLWWGdd/hmSWq8hQezOC4LviawdT1gj+b7JbqmFiphcT5orxak4WOi5jh+DqLppUcojcfHlPGZ508KtoHGabtgDmG8qWsTJyWWyMx4JtSiYOFup+PQxvoAc5FO"                                                                     
}

Polling the status:

$ curl --request POST http://localhost:8080/index.php/auth/status?accesstoken=9VeXzLiLWWGdd/hmSWq8hQezOC4LviawdT1gj%2Bb7JbqmFiphcT5orxak4WOi5jh%2BDqLppUcojcfHlPWyMx4JtSiYOFup%2BPQxvoAc5FO | python -m json.tool
{                                                                                                                                                                                                                         
    "status": 0,                                                                                                                                                                                                          
    "token": null                                                                                                                                                                                                         
} 

Logging in with the URL above using an incognito window in the browser of choice:
bildschirmfoto von 2016-05-25 13-46-19
bildschirmfoto von 2016-05-25 13-46-26
bildschirmfoto von 2016-05-25 13-46-42

Polling the status again:

$ curl --request POST http://localhost:8080/index.php/auth/status?accesstoken=9VeXzLiLWWGdd/hmSWq8hQezOC4LviawdT1gj%2Bb7JbqmFiphcT5orxak4WOi5jh%2BDqLppUcojcfHlPGZ508KtoHGabtgDmG8qWsTJyWWyMx4JtSiYOFup%2BPQxvoAc5FO | python -m json.tool
{                                                                                                                                                                                                                         
    "status": 1,                                                                                                                                                                                                          
    "token": "tj2MwhtVodHkP8FUlPp26GhTpyOD6DO0uQ+faPyGY4V5bmfDQoe4ugugyoFibe/kUrIHEgG91ohuP9fdd1UpGQD0hMSTi0bE0OcqRApfEdiC4D/P4/oh/otMtcrejt2z"                                                                           
}

@ChristophWurst
ChristophWurst force-pushed the browser-based-client-login branch from d564e0f to 7ffe844 Compare May 25, 2016 11:47
@ChristophWurst

Copy link
Copy Markdown
Contributor Author

Q: How does the server determine whether external identity providers (namely apache auth) are used? I see code in base.php trying to log in with apache, but that code only checks if an active session exists. What if the backend is used but no session is active? The client would still need to authenticate on it, wouldn't it?

Not sure if that's reliable, but we could loop through the user backends in OC_User and if there is at least one backend implementing IApacheBackend we consider the instance to be authenticated externally.

Q: Is apache auth the only possible external auth mechanism we support? If we want to let the client know whether the token can be generated via the simple route or if a browser must be used we need to know if external auth is used.

@danimo @PVince81 @DeepDiver1975 @rullzer @butonic I need some help with this

@ChristophWurst

Copy link
Copy Markdown
Contributor Author

If we go with browser login only as suggested by @rullzer in #24794 (comment) we wouldn't need the decision described above.

@danimo

danimo commented May 25, 2016

Copy link
Copy Markdown
Contributor

@ChristophWurst: Hmm, @rullzer was referring to only accepting tokens for WebDAV. This is about what we accept for acquiring the token. right?

@ChristophWurst

Copy link
Copy Markdown
Contributor Author

I would even go a step further and force clients to use the weblogin method.

in any case, would that be an option? How will that look on the client? Is the browser window embedded in the setup window of the client or is that an external one?

@ChristophWurst

Copy link
Copy Markdown
Contributor Author

but yes, this is purely about acquiring the token

@ChristophWurst
ChristophWurst force-pushed the browser-based-client-login branch from 7ffe844 to a725826 Compare May 25, 2016 16:15
@butonic

butonic commented May 25, 2016

Copy link
Copy Markdown
Contributor

Apache based auth is optional and will be used if a registered IApacheBackend returns true for isSessionActive(). There are oc instances that use ldap based basic auth for the desktop client and shibboleth / saml for the web interface. The same customers of course are asking for kerberos or WIA support in the client so they can go full SAML. Typically LDAP / Basic auth is only a migration path.

That being said, token based auth should give even more control to users and administrators in case of a lost device, so I guess forcing browser only login is a safe bet. It would be great if admins can generate a token for a user so he can preconfigure clients in an enterprise environment, but that can be added as a followup pr.

I guess smartcards are then becoming only a second factor, so also out of scope for this PR.

@ChristophWurst

Copy link
Copy Markdown
Contributor Author

copied from IRC for future reference:

[19:41:08] butonic_: ChristophWurst: currently it is not possible to simply check if apache auth is enabled. you could try iterating over the user backends and check if any instance implements the IApacheBackend. Noone redirects an unauthenticated user ... there is a fallback in base.php I think that redirects to the login page. In case of user_shibboleth the mod_shib2 apache module may redirect to the idp

@butonic thanks a lot for clarifying. I think I get the picture now.

This basically means the workflow we designed will not work here as in that workflow we assumed that ownCloud gets a request first, which would be used to initialize the asynchronous login process we track with a temporary token.

@butonic

butonic commented May 26, 2016 •

Copy link
Copy Markdown
Contributor

Um ... I admit I don't seem to get the full picture. If you want to make token based auth work with shibboleth, that as well is possible. You can configure mod shib to allow a user access to the login page, even when he does not have a shibboleth session. Some customers use that to show the login page and a 'login via IDP foo company' and 'login via bar company' buttons. So you can do a normal basic auth login (or IIUC a token based login) but if a shibboleth session is active user_shibboleth will login the user from the shibboleth token.

For seamless SSO in this scenario (called Passive Login in shibboleth lingua) we still need to add some js to the login page but that typically happens as part of consulting or theming. I added an issue to user_shibboleth to make it a one click option.

@ChristophWurst

Copy link
Copy Markdown
Contributor Author

@butonic if possible, we'd need to configure shib to not redirect on the /auth/start and /auth/status routes. On all other routes the client or the external browser should be redirected to the identity provider, do the login and come back afterwards.

@butonic

butonic commented May 30, 2016

Copy link
Copy Markdown
Contributor

If it is only about disabling shibboleth for a specific URL we are already doing that for css, js and other things: https://doc.owncloud.org/server/9.0/admin_manual/enterprise_user_management/user_auth_shibboleth.html?highlight=shibboleth#apache-configuration

For the above URLs we only need to add, eg:

#
# Shibboleth is disabled for token based auth
#
<Location ~ "/oc-shib/auth/(start|status)">
  AuthType None
  Require all granted
</Location>

However, the auth URLs look like pretty URLs, so we might need an index.php in the location.

@ChristophWurst
ChristophWurst force-pushed the browser-based-client-login branch 2 times, most recently from ec6c367 to ac760da Compare May 30, 2016 09:57
@DeepDiver1975

Copy link
Copy Markdown
Contributor

If you want to make token based auth work with shibboleth, that as well is possible.

We have to carefully coordinate this change with the client devs(desktop and mobile) as well as with documentation and support. This has major impact on many installations.

I'm all-in to walk this path if we do NOT break the current behavior where the clients popup the IdP webui for login.

@ChristophWurst

Copy link
Copy Markdown
Contributor Author

Tested with Shibboleth: works 💃

The following config is needed to allow two of the three routes:

# Shibboleth is disabled for the following location to allow token generation                                                                                                       
<Location ~ "/oc-shib/index.php/auth/(start|status)">                                                                                                                                       
  Satisfy Any
  Allow from all                                                                                                                                                                           
  AuthType None
  Require all granted
</Location>

@ChristophWurst

Copy link
Copy Markdown
Contributor Author

Let's do the client auth detection in a follow-up PR.

@PVince81 @DeepDiver1975 @rullzer @danimo @nickvergessen @davivel review/test please

Comment thread core/Application.php Outdated
$container->registerService('TwoFactorAuthManager', function(SimpleContainer $c) {
return $c->query('ServerContainer')->getTwoFactorAuthManager();
});
$container->registerService('OC\Authentication\ClientLogin\IClientLoginCoordinator', function (SimpleContainer $c) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hu? this looks redundant, just add ->query('ServerContainer') above?

@ChristophWurst
ChristophWurst force-pushed the browser-based-client-login branch from 1f46355 to 164bce5 Compare June 28, 2016 08:55
@ChristophWurst

Copy link
Copy Markdown
Contributor Author

Updated the PR to make the authorization an explicit action by the user by clicking a button.
bildschirmfoto von 2016-06-28 13-56-55
bildschirmfoto von 2016-06-28 13-57-06

$token = $this->random->generate(128);
// Password set to null, hence there will be no password check in OC\User\Session::validateSession
// Therefore we also do not need to loginname (we don't know it anyway)
$this->tokenProvider->generateToken($token, $accessToken->getUid(), '?', null, $accessToken->getClientName(), IToken::PERMANENT_TOKEN);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we check the login name when logging in via token, hence '?' fails.

@ogoffart

Copy link
Copy Markdown

Note that it should be possible to somehow login without knowing the username, only with the token. Or the poll call should also return the username.

Because in the client's wizard, we don't want to ask any information from the user. The user would just authenticate in the browser, and would not enter its username, (or anything)

public function login($uid, $password) {
$this->session->regenerateId();

if ($this->validateToken($password, $uid)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChristophWurst mind having a look if this change causes any issues?

This is necessary to allow browser based login.

@ogoffart FYU

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need some context here, it's been some time since I wrote that code 🙈.

What is the method called with here? The login password or an app password? Is this change specific to this URL or does that fix an issue in general?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the password is a generated token based on the browser client login workflow.

the login name with the token is stored as '?' and therefor the token based auth fails

@DeepDiver1975
DeepDiver1975 force-pushed the browser-based-client-login branch from 67b2415 to dda616c Compare August 13, 2016 14:54
@ogoffart

Copy link
Copy Markdown

@davivel

@DeepDiver1975
DeepDiver1975 force-pushed the browser-based-client-login branch from dda616c to 3eee237 Compare October 12, 2016 14:34
@ogoffart

Copy link
Copy Markdown

It is impossible to implement the wizard on the client if the final reply don't tell me the username. (see #24835 (comment) )

@davivel

davivel commented Oct 19, 2016 •

Copy link
Copy Markdown

@ogoffart, we had that problem in the past with SAML. We added an extra request to GET index.php/ocs/cloud/user right after receiving the token. Could that work for you here?

@ogoffart

Copy link
Copy Markdown

@davivel: no, that would not work. In order to call the ocs/cloud/user API we need to be autenticated. And to do that, we need to use the basic auth with both the token and the user. But we don't have the user.

@DeepDiver1975

Copy link
Copy Markdown
Contributor

@davivel: no, that would not work. In order to call the ocs/cloud/user API we need to be autenticated. And to do that, we need to use the basic auth with both the token and the user. But we don't have the user.

once you have the token back this should be enough to call /ocs/cloud/user - otherwise we failed with this api completly

@Peter-Prochaska time to dive into the mess 😉

@ogoffart

Copy link
Copy Markdown

The problem is, what to use as username in the basic auth?
It seems it does not matter, i can put any user. Well, then it can work.

I just need to make sure the user is the same user as the one expected, otherwise we woould mess up the sync by merging both accounts.

@DeepDiver1975
DeepDiver1975 deleted the browser-based-client-login branch November 21, 2016 11:10
@DeepDiver1975

Copy link
Copy Markdown
Contributor

we will introduce OAuth for any future client integration

@PVince81

Copy link
Copy Markdown
Contributor

#10400

@lock

lock Bot commented Aug 4, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser-based client login

10 participants