Merge pull request #11396 from nextcloud/wellknown-webfinger

adding .well-known/webfinger
This commit is contained in:
Morris Jobke 2018-10-24 14:51:15 +02:00 committed by GitHub
commit df6e9109c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 43 additions and 8 deletions

View File

@ -60,6 +60,7 @@
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L] RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L] RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L] RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L] RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
RewriteRule ^remote/(.*) remote.php [QSA,L] RewriteRule ^remote/(.*) remote.php [QSA,L]

View File

@ -52,9 +52,14 @@
* @param url the URL to test * @param url the URL to test
* @param placeholderUrl the placeholder URL - can be found at oc_defaults.docPlaceholderUrl * @param placeholderUrl the placeholder URL - can be found at oc_defaults.docPlaceholderUrl
* @param {boolean} runCheck if this is set to false the check is skipped and no error is returned * @param {boolean} runCheck if this is set to false the check is skipped and no error is returned
* @param {int} expectedStatus the expected HTTP status to be returned by the URL, 207 by default
* @return $.Deferred object resolved with an array of error messages * @return $.Deferred object resolved with an array of error messages
*/ */
checkWellKnownUrl: function(url, placeholderUrl, runCheck) { checkWellKnownUrl: function(url, placeholderUrl, runCheck, expectedStatus) {
if (expectedStatus === undefined) {
expectedStatus = 207;
}
var deferred = $.Deferred(); var deferred = $.Deferred();
if(runCheck === false) { if(runCheck === false) {
@ -63,7 +68,7 @@
} }
var afterCall = function(xhr) { var afterCall = function(xhr) {
var messages = []; var messages = [];
if (xhr.status !== 207) { if (xhr.status !== expectedStatus) {
var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL'); var docUrl = placeholderUrl.replace('PLACEHOLDER', 'admin-setup-well-known-URL');
messages.push({ messages.push({
msg: t('core', 'Your web server is not properly set up to resolve "{url}". Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }), msg: t('core', 'Your web server is not properly set up to resolve "{url}". Further information can be found in the <a target="_blank" rel="noreferrer noopener" href="{docLink}">documentation</a>.', { docLink: docUrl, url: url }),

View File

@ -61,8 +61,8 @@ describe('OC.SetupChecks tests', function() {
}); });
describe('checkWellKnownUrl', function() { describe('checkWellKnownUrl', function() {
it('should fail with another response status code than 207', function(done) { it('should fail with another response status code than the expected one', function(done) {
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true); var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207);
suite.server.requests[0].respond(200); suite.server.requests[0].respond(200);
@ -75,7 +75,18 @@ describe('OC.SetupChecks tests', function() {
}); });
}); });
it('should return no error with a response status code of 207', function(done) { it('should return no error with the expected response status code', function(done) {
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true, 207);
suite.server.requests[0].respond(207);
async.done(function( data, s, x ){
expect(data).toEqual([]);
done();
});
});
it('should return no error with the default expected response status code', function(done) {
var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true); var async = OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', 'http://example.org/PLACEHOLDER', true);
suite.server.requests[0].respond(207); suite.server.requests[0].respond(207);

View File

@ -54,7 +54,7 @@ try {
list($service) = explode('/', $pathInfo); list($service) = explode('/', $pathInfo);
} }
$file = \OC::$server->getConfig()->getAppValue('core', 'public_' . strip_tags($service)); $file = \OC::$server->getConfig()->getAppValue('core', 'public_' . strip_tags($service));
if ($file === null) { if ($file === '') {
http_response_code(404); http_response_code(404);
exit; exit;
} }

View File

@ -121,6 +121,8 @@ class Application extends App {
Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');
Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig');
} }
/** /**
@ -152,4 +154,18 @@ class Application extends App {
$hooks = $this->getContainer()->query(Hooks::class); $hooks = $this->getContainer()->query(Hooks::class);
$hooks->onChangeEmail($parameters['user'], $parameters['old_value']); $hooks->onChangeEmail($parameters['user'], $parameters['old_value']);
} }
/**
* @param array $settings
*/
public function extendJsConfig(array $settings) {
$appConfig = json_decode($settings['array']['oc_appconfig'], true);
$publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', '');
if (!empty($publicWebFinger)) {
$appConfig['core']['public_webfinger'] = $publicWebFinger;
}
$settings['array']['oc_appconfig'] = json_encode($appConfig);
}
} }

View File

@ -248,13 +248,14 @@ $(document).ready(function(){
// run setup checks then gather error messages // run setup checks then gather error messages
$.when( $.when(
OC.SetupChecks.checkWebDAV(), OC.SetupChecks.checkWebDAV(),
OC.SetupChecks.checkWellKnownUrl('/.well-known/webfinger', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true && !!oc_appconfig.core.public_webfinger, 200),
OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true), OC.SetupChecks.checkWellKnownUrl('/.well-known/caldav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true), OC.SetupChecks.checkWellKnownUrl('/.well-known/carddav', oc_defaults.docPlaceholderUrl, $('#postsetupchecks').data('check-wellknown') === true),
OC.SetupChecks.checkSetup(), OC.SetupChecks.checkSetup(),
OC.SetupChecks.checkGeneric(), OC.SetupChecks.checkGeneric(),
OC.SetupChecks.checkDataProtected() OC.SetupChecks.checkDataProtected()
).then(function(check1, check2, check3, check4, check5, check6) { ).then(function(check1, check2, check3, check4, check5, check6, check7) {
var messages = [].concat(check1, check2, check3, check4, check5, check6); var messages = [].concat(check1, check2, check3, check4, check5, check6, check7);
var $el = $('#postsetupchecks'); var $el = $('#postsetupchecks');
$('#security-warning-state-loading').addClass('hidden'); $('#security-warning-state-loading').addClass('hidden');

View File

@ -38,6 +38,7 @@ RewriteEngine on
RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L] RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L] RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
RewriteRule ^\.well-known/webfinger /public.php?service=webfinger [QSA,L]
RewriteRule ^\.well-known/carddav /remote.php/carddav/ [R=301,L] RewriteRule ^\.well-known/carddav /remote.php/carddav/ [R=301,L]
RewriteRule ^\.well-known/caldav /remote.php/caldav/ [R=301,L] RewriteRule ^\.well-known/caldav /remote.php/caldav/ [R=301,L]
RewriteRule ^apps/calendar/caldav\.php remote.php/caldav/ [QSA,L] RewriteRule ^apps/calendar/caldav\.php remote.php/caldav/ [QSA,L]