Merge pull request #47945 from nextcloud/fix/external-storage-creds

pull/47949/head
John Molakvoæ 8 months ago committed by GitHub
commit 032f17c795
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      apps/files_external/appinfo/routes.php
  2. 28
      apps/files_external/lib/Controller/ApiController.php
  3. 70
      apps/files_external/src/actions/enterCredentialsAction.ts
  4. 86
      apps/files_external/src/views/CredentialsDialog.vue
  5. 2
      dist/4076-4076.js
  6. 213
      dist/4076-4076.js.license
  7. 1
      dist/4076-4076.js.map
  8. 1
      dist/4076-4076.js.map.license
  9. 4
      dist/files_external-init.js
  10. 2
      dist/files_external-init.js.map

@ -40,10 +40,5 @@ return [
'url' => '/api/v1/mounts',
'verb' => 'GET',
],
[
'name' => 'Api#askNativeAuth',
'url' => '/api/v1/auth',
'verb' => 'GET',
],
],
];

@ -15,7 +15,6 @@ use OCA\Files_External\Service\UserGlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\OpenAPI;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
@ -103,31 +102,4 @@ class ApiController extends OCSController {
return new DataResponse($entries);
}
/**
* Ask for credentials using a browser's native basic auth prompt
* Then returns it if provided
*/
#[NoAdminRequired]
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
public function askNativeAuth(): DataResponse {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
$response = new DataResponse([], Http::STATUS_UNAUTHORIZED);
$response->addHeader('WWW-Authenticate', 'Basic realm="Storage authentification needed"');
return $response;
}
$user = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];
// Reset auth
unset($_SERVER['PHP_AUTH_USER']);
unset($_SERVER['PHP_AUTH_PW']);
// Using 401 again to ensure we clear any cached Authorization
return new DataResponse([
'user' => $user,
'password' => $password,
], Http::STATUS_UNAUTHORIZED);
}
}

@ -7,29 +7,39 @@ import type { AxiosResponse } from '@nextcloud/axios'
import type { Node } from '@nextcloud/files'
import type { StorageConfig } from '../services/externalStorage'
import { generateOcsUrl, generateUrl } from '@nextcloud/router'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { generateUrl } from '@nextcloud/router'
import { showError, showSuccess, spawnDialog } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import LoginSvg from '@mdi/svg/svg/login.svg?raw'
import Vue from 'vue'
import Vue, { defineAsyncComponent } from 'vue'
import { FileAction, DefaultType } from '@nextcloud/files'
import { STORAGE_STATUS, isMissingAuthConfig } from '../utils/credentialsUtils'
import { isNodeExternalStorage } from '../utils/externalStorageUtils'
type OCSAuthResponse = {
ocs: {
meta: {
status: string
statuscode: number
message: string
},
data: {
user?: string,
password?: string,
}
type CredentialResponse = {
login?: string,
password?: string,
}
async function setCredentials(node: Node, login: string, password: string): Promise<null|true> {
const configResponse = await axios.put(generateUrl('apps/files_external/userglobalstorages/{id}', node.attributes), {
backendOptions: { user: login, password },
}) as AxiosResponse<StorageConfig>
const config = configResponse.data
if (config.status !== STORAGE_STATUS.SUCCESS) {
showError(t('files_external', 'Unable to update this external storage config. {statusMessage}', {
statusMessage: config?.statusMessage || '',
}))
return null
}
// Success update config attribute
showSuccess(t('files_external', 'New configuration successfully saved'))
Vue.set(node.attributes, 'config', config)
return true
}
export const action = new FileAction({
@ -57,30 +67,16 @@ export const action = new FileAction({
},
async exec(node: Node) {
// always resolve auth request, we'll process the data afterwards
// Using fetch as axios have integrated auth handling and X-Requested-With header
const response = await fetch(generateOcsUrl('/apps/files_external/api/v1/auth'), {
headers: new Headers({ Accept: 'application/json' }),
credentials: 'include',
})
const data = (await response?.json() || {}) as OCSAuthResponse
if (data.ocs.data.user && data.ocs.data.password) {
const configResponse = await axios.put(generateUrl('apps/files_external/userglobalstorages/{id}', node.attributes), {
backendOptions: data.ocs.data,
}) as AxiosResponse<StorageConfig>
const config = configResponse.data
if (config.status !== STORAGE_STATUS.SUCCESS) {
showError(t('files_external', 'Unable to update this external storage config. {statusMessage}', {
statusMessage: config?.statusMessage || '',
}))
return null
}
const { login, password } = await new Promise<CredentialResponse>(resolve => spawnDialog(
defineAsyncComponent(() => import('../views/CredentialsDialog.vue')),
{},
(args) => {
resolve(args as CredentialResponse)
},
))
// Success update config attribute
showSuccess(t('files_external', 'New configuration successfully saved'))
Vue.set(node.attributes, 'config', config)
if (login && password) {
return await setCredentials(node, login, password)
}
return null

@ -0,0 +1,86 @@
<!--
- SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<NcDialog :buttons="dialogButtons"
class="external-storage-auth"
close-on-click-outside
data-cy-external-storage-auth
is-form
:name="t('files_external', 'Storage credentials')"
out-transition
@submit="$emit('close', {login, password})"
@update:open="$emit('close')">
<!-- Header -->
<NcNoteCard class="external-storage-auth__header"
:text="t('files_external', 'To access the storage, you need to provide the authentification informations.')"
type="info" />
<!-- Login -->
<NcTextField ref="login"
class="external-storage-auth__login"
data-cy-external-storage-auth-dialog-login
:label="t('files_external', 'Login')"
:placeholder="t('files_external', 'Enter the storage login')"
minlength="2"
name="login"
required
:value.sync="login" />
<!-- Password -->
<NcPasswordField ref="password"
class="external-storage-auth__password"
data-cy-external-storage-auth-dialog-password
:label="t('files_external', 'Password')"
:placeholder="t('files_external', 'Enter the storage password')"
name="password"
required
:value.sync="password" />
</NcDialog>
</template>
<script lang="ts">
import { defineComponent } from 'vue'
import { t } from '@nextcloud/l10n'
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import NcPasswordField from '@nextcloud/vue/dist/Components/NcPasswordField.js'
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
export default defineComponent({
name: 'CredentialsDialog',
components: {
NcDialog,
NcNoteCard,
NcTextField,
NcPasswordField,
},
setup() {
return {
t,
}
},
data() {
return {
login: '',
password: '',
}
},
computed: {
dialogButtons() {
return [{
label: t('files_external', 'Submit'),
type: 'primary',
nativeType: 'submit',
}]
},
},
})
</script>

2
dist/4076-4076.js vendored

@ -0,0 +1,2 @@
"use strict";(self.webpackChunknextcloud=self.webpackChunknextcloud||[]).push([[4076],{11695:(e,t,a)=>{a.r(t),a.d(t,{default:()=>d});var s=a(85471),o=a(53334),l=a(94219),n=a(80910),r=a(16044),i=a(82182);const u=(0,s.pM)({name:"CredentialsDialog",components:{NcDialog:l.A,NcNoteCard:n.A,NcTextField:i.A,NcPasswordField:r.A},setup:()=>({t:o.t}),data:()=>({login:"",password:""}),computed:{dialogButtons:()=>[{label:(0,o.t)("files_external","Submit"),type:"primary",nativeType:"submit"}]}}),d=(0,a(14486).A)(u,(function(){var e=this,t=e._self._c;return e._self._setupProxy,t("NcDialog",{staticClass:"external-storage-auth",attrs:{buttons:e.dialogButtons,"close-on-click-outside":"","data-cy-external-storage-auth":"","is-form":"",name:e.t("files_external","Storage credentials"),"out-transition":""},on:{submit:function(t){return e.$emit("close",{login:e.login,password:e.password})},"update:open":function(t){return e.$emit("close")}}},[t("NcNoteCard",{staticClass:"external-storage-auth__header",attrs:{text:e.t("files_external","To access the storage, you need to provide the authentification informations."),type:"info"}}),e._v(" "),t("NcTextField",{ref:"login",staticClass:"external-storage-auth__login",attrs:{"data-cy-external-storage-auth-dialog-login":"",label:e.t("files_external","Login"),placeholder:e.t("files_external","Enter the storage login"),minlength:"2",name:"login",required:"",value:e.login},on:{"update:value":function(t){e.login=t}}}),e._v(" "),t("NcPasswordField",{ref:"password",staticClass:"external-storage-auth__password",attrs:{"data-cy-external-storage-auth-dialog-password":"",label:e.t("files_external","Password"),placeholder:e.t("files_external","Enter the storage password"),name:"password",required:"",value:e.password},on:{"update:value":function(t){e.password=t}}})],1)}),[],!1,null,null,null).exports}}]);
//# sourceMappingURL=4076-4076.js.map?v=c244d3fd930f6d6bf2c5

@ -0,0 +1,213 @@
SPDX-License-Identifier: MIT
SPDX-License-Identifier: ISC
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-License-Identifier: BSD-3-Clause
SPDX-License-Identifier: AGPL-3.0-or-later
SPDX-License-Identifier: (MPL-2.0 OR Apache-2.0)
SPDX-FileCopyrightText: inherits developers
SPDX-FileCopyrightText: escape-html developers
SPDX-FileCopyrightText: debounce developers
SPDX-FileCopyrightText: assert developers
SPDX-FileCopyrightText: Tobias Koppers @sokra
SPDX-FileCopyrightText: T. Jameson Little <t.jameson.little@gmail.com>
SPDX-FileCopyrightText: Roman Shtylman <shtylman@gmail.com>
SPDX-FileCopyrightText: Raynos <raynos2@gmail.com>
SPDX-FileCopyrightText: Nextcloud GmbH and Nextcloud contributors
SPDX-FileCopyrightText: Matt Zabriskie
SPDX-FileCopyrightText: Joyent
SPDX-FileCopyrightText: Jordan Harband <ljharb@gmail.com>
SPDX-FileCopyrightText: Jordan Harband
SPDX-FileCopyrightText: John-David Dalton <john.david.dalton@gmail.com> (http://allyoucanleet.com/)
SPDX-FileCopyrightText: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
SPDX-FileCopyrightText: Guillaume Chau <guillaume.b.chau@gmail.com>
SPDX-FileCopyrightText: GitHub Inc.
SPDX-FileCopyrightText: Feross Aboukhadijeh
SPDX-FileCopyrightText: Evan You
SPDX-FileCopyrightText: Dr.-Ing. Mario Heiderich, Cure53 <mario@cure53.de> (https://cure53.de/)
SPDX-FileCopyrightText: David Clark
SPDX-FileCopyrightText: Christoph Wurst
SPDX-FileCopyrightText: Anthony Fu <https://github.com/antfu>
SPDX-FileCopyrightText: Andris Reinman
This file is generated from multiple sources. Included packages:
- @nextcloud/auth
- version: 2.4.0
- license: GPL-3.0-or-later
- @nextcloud/axios
- version: 2.5.0
- license: GPL-3.0-or-later
- @nextcloud/browser-storage
- version: 0.4.0
- license: GPL-3.0-or-later
- semver
- version: 7.6.3
- license: ISC
- @nextcloud/event-bus
- version: 3.3.1
- license: GPL-3.0-or-later
- @nextcloud/initial-state
- version: 2.2.0
- license: GPL-3.0-or-later
- @nextcloud/l10n
- version: 3.1.0
- license: GPL-3.0-or-later
- @nextcloud/logger
- version: 3.0.2
- license: GPL-3.0-or-later
- @nextcloud/router
- version: 3.0.1
- license: GPL-3.0-or-later
- @nextcloud/vue
- version: 8.17.1
- license: AGPL-3.0-or-later
- @vueuse/core
- version: 11.0.3
- license: MIT
- @vueuse/shared
- version: 11.0.3
- license: MIT
- assert
- version: 2.1.0
- license: MIT
- available-typed-arrays
- version: 1.0.7
- license: MIT
- axios
- version: 1.7.7
- license: MIT
- base64-js
- version: 1.5.1
- license: MIT
- call-bind
- version: 1.0.7
- license: MIT
- console-browserify
- version: 1.2.0
- license: MIT
- css-loader
- version: 6.11.0
- license: MIT
- debounce
- version: 2.1.0
- license: MIT
- define-data-property
- version: 1.1.4
- license: MIT
- define-properties
- version: 1.2.1
- license: MIT
- dompurify
- version: 3.1.6
- license: (MPL-2.0 OR Apache-2.0)
- es-define-property
- version: 1.0.0
- license: MIT
- es-errors
- version: 1.3.0
- license: MIT
- escape-html
- version: 1.0.3
- license: MIT
- floating-vue
- version: 1.0.0-beta.19
- license: MIT
- focus-trap
- version: 7.5.4
- license: MIT
- for-each
- version: 0.3.3
- license: MIT
- function-bind
- version: 1.1.2
- license: MIT
- get-intrinsic
- version: 1.2.4
- license: MIT
- gopd
- version: 1.0.1
- license: MIT
- has-property-descriptors
- version: 1.0.2
- license: MIT
- has-proto
- version: 1.0.3
- license: MIT
- has-symbols
- version: 1.0.3
- license: MIT
- has-tostringtag
- version: 1.0.2
- license: MIT
- hasown
- version: 2.0.2
- license: MIT
- ieee754
- version: 1.2.1
- license: BSD-3-Clause
- inherits
- version: 2.0.4
- license: ISC
- is-arguments
- version: 1.1.1
- license: MIT
- is-callable
- version: 1.2.7
- license: MIT
- is-generator-function
- version: 1.0.10
- license: MIT
- is-nan
- version: 1.3.2
- license: MIT
- is-typed-array
- version: 1.1.13
- license: MIT
- lodash.get
- version: 4.4.2
- license: MIT
- node-gettext
- version: 3.0.0
- license: MIT
- buffer
- version: 6.0.3
- license: MIT
- object-is
- version: 1.1.6
- license: MIT
- object-keys
- version: 1.1.1
- license: MIT
- object.assign
- version: 4.1.5
- license: MIT
- possible-typed-array-names
- version: 1.0.0
- license: MIT
- process
- version: 0.11.10
- license: MIT
- set-function-length
- version: 1.2.2
- license: MIT
- style-loader
- version: 3.3.4
- license: MIT
- tabbable
- version: 6.2.0
- license: MIT
- util
- version: 0.12.5
- license: MIT
- vue-loader
- version: 15.11.1
- license: MIT
- vue
- version: 2.7.16
- license: MIT
- which-typed-array
- version: 1.1.15
- license: MIT
- nextcloud
- version: 1.0.0
- license: AGPL-3.0-or-later

@ -0,0 +1 @@
{"version":3,"file":"4076-4076.js?v=c244d3fd930f6d6bf2c5","mappings":"qIAAA,I,kEAMA,MCNiQ,GDMlPA,EAAAA,EAAAA,IAAgB,CAC3BC,KAAM,oBACNC,WAAY,CACRC,SAAQ,IACRC,WAAU,IACVC,YAAW,IACXC,gBAAeA,EAAAA,GAEnBC,MAAKA,KACM,CACHC,EAACA,EAAAA,IAGTC,KAAIA,KACO,CACHC,MAAO,GACPC,SAAU,KAGlBC,SAAU,CACNC,cAAaA,IACF,CAAC,CACAC,OAAON,EAAAA,EAAAA,GAAE,iBAAkB,UAC3BO,KAAM,UACNC,WAAY,cEZhC,GAXgB,E,SAAA,GACd,GFRW,WAAkB,IAAIC,EAAIC,KAAKC,EAAGF,EAAIG,MAAMD,GAAgC,OAAtBF,EAAIG,MAAMC,YAAmBF,EAAG,WAAW,CAACG,YAAY,wBAAwBC,MAAM,CAAC,QAAUN,EAAIJ,cAAc,yBAAyB,GAAG,gCAAgC,GAAG,UAAU,GAAG,KAAOI,EAAIT,EAAE,iBAAkB,uBAAuB,iBAAiB,IAAIgB,GAAG,CAAC,OAAS,SAASC,GAAQ,OAAOR,EAAIS,MAAM,QAAS,CAAChB,MAAOO,EAAIP,MAAOC,SAAUM,EAAIN,UAAU,EAAE,cAAc,SAASc,GAAQ,OAAOR,EAAIS,MAAM,QAAQ,IAAI,CAACP,EAAG,aAAa,CAACG,YAAY,gCAAgCC,MAAM,CAAC,KAAON,EAAIT,EAAE,iBAAkB,iFAAiF,KAAO,UAAUS,EAAIU,GAAG,KAAKR,EAAG,cAAc,CAACS,IAAI,QAAQN,YAAY,+BAA+BC,MAAM,CAAC,6CAA6C,GAAG,MAAQN,EAAIT,EAAE,iBAAkB,SAAS,YAAcS,EAAIT,EAAE,iBAAkB,2BAA2B,UAAY,IAAI,KAAO,QAAQ,SAAW,GAAG,MAAQS,EAAIP,OAAOc,GAAG,CAAC,eAAe,SAASC,GAAQR,EAAIP,MAAMe,CAAM,KAAKR,EAAIU,GAAG,KAAKR,EAAG,kBAAkB,CAACS,IAAI,WAAWN,YAAY,kCAAkCC,MAAM,CAAC,gDAAgD,GAAG,MAAQN,EAAIT,EAAE,iBAAkB,YAAY,YAAcS,EAAIT,EAAE,iBAAkB,8BAA8B,KAAO,WAAW,SAAW,GAAG,MAAQS,EAAIN,UAAUa,GAAG,CAAC,eAAe,SAASC,GAAQR,EAAIN,SAASc,CAAM,MAAM,EAC/5C,GACsB,IESpB,EACA,KACA,KACA,MAI8B,O","sources":["webpack:///nextcloud/apps/files_external/src/views/CredentialsDialog.vue","webpack:///nextcloud/apps/files_external/src/views/CredentialsDialog.vue?vue&type=script&lang=ts","webpack://nextcloud/./apps/files_external/src/views/CredentialsDialog.vue?7767"],"sourcesContent":["var render = function render(){var _vm=this,_c=_vm._self._c,_setup=_vm._self._setupProxy;return _c('NcDialog',{staticClass:\"external-storage-auth\",attrs:{\"buttons\":_vm.dialogButtons,\"close-on-click-outside\":\"\",\"data-cy-external-storage-auth\":\"\",\"is-form\":\"\",\"name\":_vm.t('files_external', 'Storage credentials'),\"out-transition\":\"\"},on:{\"submit\":function($event){return _vm.$emit('close', {login: _vm.login, password: _vm.password})},\"update:open\":function($event){return _vm.$emit('close')}}},[_c('NcNoteCard',{staticClass:\"external-storage-auth__header\",attrs:{\"text\":_vm.t('files_external', 'To access the storage, you need to provide the authentification informations.'),\"type\":\"info\"}}),_vm._v(\" \"),_c('NcTextField',{ref:\"login\",staticClass:\"external-storage-auth__login\",attrs:{\"data-cy-external-storage-auth-dialog-login\":\"\",\"label\":_vm.t('files_external', 'Login'),\"placeholder\":_vm.t('files_external', 'Enter the storage login'),\"minlength\":\"2\",\"name\":\"login\",\"required\":\"\",\"value\":_vm.login},on:{\"update:value\":function($event){_vm.login=$event}}}),_vm._v(\" \"),_c('NcPasswordField',{ref:\"password\",staticClass:\"external-storage-auth__password\",attrs:{\"data-cy-external-storage-auth-dialog-password\":\"\",\"label\":_vm.t('files_external', 'Password'),\"placeholder\":_vm.t('files_external', 'Enter the storage password'),\"name\":\"password\",\"required\":\"\",\"value\":_vm.password},on:{\"update:value\":function($event){_vm.password=$event}}})],1)\n}\nvar staticRenderFns = []\n\nexport { render, staticRenderFns }","import mod from \"-!../../../../node_modules/babel-loader/lib/index.js!../../../../node_modules/ts-loader/index.js??clonedRuleSet-4.use[1]!../../../../node_modules/vue-loader/lib/index.js??vue-loader-options!./CredentialsDialog.vue?vue&type=script&lang=ts\"; export default mod; export * from \"-!../../../../node_modules/babel-loader/lib/index.js!../../../../node_modules/ts-loader/index.js??clonedRuleSet-4.use[1]!../../../../node_modules/vue-loader/lib/index.js??vue-loader-options!./CredentialsDialog.vue?vue&type=script&lang=ts\"","import { render, staticRenderFns } from \"./CredentialsDialog.vue?vue&type=template&id=086413e6\"\nimport script from \"./CredentialsDialog.vue?vue&type=script&lang=ts\"\nexport * from \"./CredentialsDialog.vue?vue&type=script&lang=ts\"\n\n\n/* normalize component */\nimport normalizer from \"!../../../../node_modules/vue-loader/lib/runtime/componentNormalizer.js\"\nvar component = normalizer(\n script,\n render,\n staticRenderFns,\n false,\n null,\n null,\n null\n \n)\n\nexport default component.exports"],"names":["defineComponent","name","components","NcDialog","NcNoteCard","NcTextField","NcPasswordField","setup","t","data","login","password","computed","dialogButtons","label","type","nativeType","_vm","this","_c","_self","_setupProxy","staticClass","attrs","on","$event","$emit","_v","ref"],"sourceRoot":""}

@ -0,0 +1 @@
4076-4076.js.license

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save