Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to use webhooks with this app? #159

Closed
pemocarlo opened this issue Mar 30, 2021 · 15 comments
Closed

[Question] How to use webhooks with this app? #159

pemocarlo opened this issue Mar 30, 2021 · 15 comments
Labels
enhancement App improviments frontend Frontend task

Comments

@pemocarlo
Copy link

Hi
First of all, thanks for the efforts to create this app, it is extremely useful. I am currently in the process of setting it up to test it. I have been able to configure the cfssl server, and now it is possible for the users to create signatures and there is a signature tab when I open the pdf sidebar.

Unfortunately, I have not been able to request file signatures using webhooks. Should I write my own webhooks and made them available at this address?
https://nextcloud.local/index.php/apps/libresign/api/v1.0

I have been trying to follow a similar example of a POST request in the documentation with no luck.

Would it be possible to provide me a minimal example or a pointer for me to move forward?

PS: I am sorry if this is an obvious question, I am a complete noob with Nextcloud.

Thank you!

@vitormattos
Copy link
Member

Hi, good to know that you liked the app's proposal.

Did you complete the setup and successfully configure in Settings> Basic Settings?

https://libresign.github.io/libresign/Getting-started.html#webhook

The first step after the configuration is OK will be to make a request to the LibreSign API requesting a document signature. The response from this endpoint is the UUID generated for the file to be signed.

https://libresign.github.io/libresign/Getting-started.html#webhook-register

For each person registered to sign a document, LibreSign checks whether it is a Nextcloud user, if it sends an email asking you to sign. If not, send the same email but the person will first see a screen for creating a user with the same email that was invited to sign the document.

It is recommended that at the moment they are new users and not existing users in Nextcloud as we have not yet implemented a flow for creating the password to sign the document for those who do not have a signature password.

After everyone signs, a POST is sent to a callback URL that is informed in the first request to register a new document to be signed. 2 fields are sent: uuid of the signed file and a file field with the signed file. This request is multipart.

@pemocarlo
Copy link
Author

pemocarlo commented Mar 30, 2021

Thank you for your reply @vitormattos, now the whole process makes more sense to me :)

Did you complete the setup and successfully configure in Settings> Basic Settings?

Yes, the email server settings are working correctly

The first step after the configuration is OK will be to make a request to the LibreSign API requesting a document signature. The response from this endpoint is the UUID generated for the file to be signed.

Most probably I am not sending the correct header or body in the request. I am currently doing this:

curl -X POST \
  http://localhost/index.php/apps/libresign/api/0.1/webhook/register \
  -H 'Accept: application/json' \
  -H 'Authorization: Basic YWRtaW46YWRtaW4='\
  -H 'Content-Type: application/json'
  -d '{
	"file": {
		"url": "[link to pdf]"
	},
	"users": [
		{
			"display_name": "[name]",
			"email": "[email]",
			"description": "Lorem ipsum"
		}
	]
}'

And getting this response

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access this resource.</p>
<hr>
<address>Apache Server at localhost Port 80</address>
</body></html>

I have a couple of questions:

  • http://localhost/index.php/apps/libresign/api/0.1/webhook/register should this be the public url instead of localhost?
  • -H 'Authorization: Basic YWRtaW46YWRtaW4='\ this is probably not correct. Should I enter here my nextcloud user credentials? Does the format -H 'Authorization: Basic [user]:[password]' work?

After everyone signs, a POST is sent to a callback URL that is informed in the first request to register a new document to be signed. 2 fields are sent: uuid of the signed file and a file field with the signed file. This request is multipart.

How can I set this callback URL?

@vitormattos
Copy link
Member

You need to generate your own base64 for the authorization header.

It is recommended to use app-password of any account of your Nextcloud.

The account used must either be in the admin group or in a group defined in Settings> Basic Settings

How can I set this callback URL?

You need to implement in the application that will integrate with LibreSign a page that receives this request and does what it needs.

The URL of this page is the callback url that you must send in all document signing requests for LibreSign

As an example, there is the GLPI plugin that allows you to sign GLPI tickets on LibreSign.

https://github.com/LibreSign/libresign-glpi

@Bolli84
Copy link

Bolli84 commented Mar 30, 2021

You mean "The account used must either be in the admin group or in a group defined in Settings> Security WEBHOOK" right?

Could you implement a button "Request signature fo mail/username field" for this file in the "Signature Detail box"? This would be a very good example to see the webhook and the procedure running.

@vitormattos
Copy link
Member

The account that I mentioned is the account to use the API and that you will use to put in the header of the HTTP request to authorize access to the API, it is not of the people who will sign the document.

The list of people who will sign the document is the one in the body of the request for the LibreSign API.

@pemocarlo
Copy link
Author

pemocarlo commented Mar 31, 2021

Hi @vitormattos ,

I tried to access the API endpoint with my Nextcloud user like this:
curl -u [my-nextcloud-username] [server-url]/index.php/apps/libresign/api/0.1/webhook/me
It prompted me for my password and after that I got the following response:
{"uid":"[my-nextcloud-username]"}
So it seems that my access to the API is correctly working

Now I tried with this same approach using the webhook/register endpoint and the example in your documentation with no luck. It returns:
Exception: Argument 1 passed to OCA\Libresign\Controller\WebhookController::register() must be of the type array, null given

Could you please give me any pointers?
Thank you in advance

@vitormattos
Copy link
Member

Hi Carlos,

Did you send a body for this request? It is necessary to send a json in the body of this request as it is in the example of the documentation.

https://libresign.github.io/libresign/Getting-started.html#headers

@pemocarlo
Copy link
Author

pemocarlo commented Mar 31, 2021

Hi @vitormattos,

Sorry for the noise, it seems it was a formatting mistake with the body, but now it is working.

Now I received the email with the signature request, but when I open it and enter the subscription password, it returns signaturefile not found

This might be, because the user and signature file are not linked, but I don't know how to do it. Until now, the user simply creates the file from the Libresign form "Create new subscription" and saves this *.pfx in files inside NextCloud.

Is there a step I am missing?

@vitormattos
Copy link
Member

This is a bug already identified.

LibreSign today only works for accounts of people who do not have a Nextcloud account. The signature password is created when the person creates the account through LibreSign.

Test with an email that is not from an existing user on Nextcloud.

@pemocarlo
Copy link
Author

Thank you for the clarification!
As you said, it works for users without a previous NextCloud account.

I will be happy to test when you develop the other features which will make this plugin fully usable. But in any case, nice work so far, this app really has great potential!

Also, would you be OK to add some of your explanations in this thread to the README? I can send a PR if you agree?

Thanks again for your time
Carlos

@vitormattos
Copy link
Member

Very happy for your comments.

I strongly believe in the potential of this application.

I will be very happy with your PR. The documentation page (it is in the docs folder) is in fact simple and needs to be increased.

@Bolli84
Copy link

Bolli84 commented Apr 1, 2021

Instead of webhook, mail, link the easiest way to sign internally would be with a simple "notification" in nextcloud directly, right?

So to say: a little dropdownbox populated with the users to select one/some and a "request signature" button internally. Since every user can have the activity stream by mail, it would work quite fine using nextcloud directly.

Maybe this approach would be the faster fix?

In the meantime, all people facing this can use the following:

  1. Add the "comments" on files app
  2. Create a comment "Please sign @username1, @username2, ..."
    Then each one should get a notification

@vitormattos
Copy link
Member

It's in the planning :-)

We are not advancing so fast in development because we do not have funding at the moment for the app.

@vitormattos
Copy link
Member

Hi @Bolli84 I created a issue with your suggestion #245

@vitormattos
Copy link
Member

We believe that the project documentation is already much better than before and we are closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement App improviments frontend Frontend task
Projects
None yet
Development

No branches or pull requests

3 participants