owncloud / docs

ownCloud Documentation (v2)
https://doc.owncloud.com
GNU Affero General Public License v3.0
56 stars 89 forks source link

Document how to trigger auth client popup with www-authenticate to OCS API (OC-RequestAppPassword) #3471

Open mrow4a opened 3 years ago

mrow4a commented 3 years ago

WHAT Needs to be Documented?

https://github.com/owncloud/core/pull/38486 https://github.com/owncloud/enterprise/issues/4196

WHERE Does This Need To Be Documented (Link)?

user manual (I think)

WHY Should This Change Be Made?

to allow users use authentication popup window in various clients e.g. Excel/Browser to authenticate to OCS API

(Optional) What Type Of Content Change Is This?

(Optional) Which Manual Does This Relate To?

Doc contents

Issue

Before owncloud 10 (seems also oc10.5) one could request password window asking username:password browsing to URL https://whatever/remote.php/dav/files/whateveruser/whatever

This behavior got depreciated in oc10

Web Browser using Headers Extensions

This method levarages adding to browser custom header using e.g. Chrome ModHeader Extension

  1. Try accessing API in web browser, it will fail

    Zrzut ekranu 2021-03-9 o 22 24 23
  2. Create APP Password in ownCloud personal settings

    Zrzut ekranu 2021-03-9 o 22 26 39
  3. Add header OC-RequestAppPassword to indicate we want to request interactive app password authentication

    Zrzut ekranu 2021-03-9 o 22 24 35
  4. Authenticate using created app password and enjoy

Zrzut ekranu 2021-03-9 o 22 24 47 Zrzut ekranu 2021-03-9 o 22 25 23

Excel

Sub owncloud()

    Range("A1").Interior.Color = vbRed
    Dim oXHTTP As Object
    Set oXHTTP = CreateObject("MSXML2.ServerXMLHTTP")

    With oXHTTP
        .Open "GET", "http://owncloudURL/ocs/v1.php/apps/files_sharing/api/v1/shares", False
        .setRequestHeader "OC-RequestAppPassword", "true"
        .send
    End With

End Sub

Javascript

Using https://github.com/owncloud/owncloud-sdk

I cannot get around problem with CORS on code in [1]. However, there is another way with using owncloud-sdk. This snippet should work but did not test as this would require me to build brand new dev environment and application, effort is pretty high (I am not JavaScript expert...)

const owncloud = require('owncloud-sdk');
let oc = new owncloud({
      baseUrl: owncloudURL,
      headers: {
        "OC-RequestAppPassword": "true"
      }
});

// Login with User and defined App Password with popup window
oc.login().then(status => {
    // STUFF
}).catch(error => {
    // HANDLE ERROR
});

// List all files for the user that authenticated with app password 
oc.files.list('/path/to/file/folder').then(files => {
    console.log(files);
}).catch(error => {
    console.log(error);
});

[1]

import 'bootstrap@4.6.0'
import $ from 'jquery'

$('button')
  .html('Click me')
  .on('click', () => {
    $.ajax({
            url: "http://localhost:8000/ocs/v1.php/apps/files_sharing/api/v1/shares",
            type : "GET",
            headers: {  
              "OCS-APIREQUEST": true,
              "OC-RequestAppPassword": "true",
            },
            tls : {
              validate: false
            },
            mode: 'cors',
            data: null,
            action: 'user',
            success: function(result) {
              console.log('ok');
            },
            error: function(result) {
              console.log('error');
            }
     });
  })

console.log('App started')
mrow4a commented 3 years ago

@mmattel I might need help on where to place this content. Any ideas?

pmaier1 commented 3 years ago

user manual (I think)

Sounds more like dev docs to me. @mmattel, please go ahead and find a good spot.

mmattel commented 3 years ago

I had an intensive and productive call today with @mrow4a. The best location will be the user manual in subsection integration. Just need a go to proceed.

pmaier1 commented 3 years ago

Ok, if you think that's the right spot, go for it.

mrow4a commented 3 years ago

@mmattel any progress? do you need any clarifications?

mrow4a commented 3 years ago

@mmattel as discussed I attempted demo.

mrow4a commented 3 years ago

@mmattel is the provided info enough?

mrow4a commented 3 years ago

updated documentation content in top post