JWT and requesting application consent; also, manual vs SDK - php

Windows 2012, PHP 7.4.
I having a really hard time getting this going, and the more I fuss with it the more confused and frustrated I become. I'm already behind on the project, so I need to start asking questions.
Working server-side: everything is handled by our application: click a button, it does all the processing without any further interact.
The task is "simple": send a PDF out for remote signing. Signature tabs are already placed in the PDF, all I have to do is SEND.
Question #1: Getting the JWT token and requesting application consent is a process, but it only has to be done once per application, right?
Question #2: The SDK seems to be overkill. I've written against REST APIs before and I'm comfortable working in that world. So, SDK vs. manually writing what I need. Advice? And whichever choice is preferred, where do I start?
Appreciate any help.

Question #1: Getting the JWT token and requesting application consent is a process, but it only has to be done once per application, right?
Getting consent from the user who will be impersonated by your app is a one time process. Depending on your use case, the "user" could be a "system user" such as finance#example.com or the user could be a specific person.
More on getting consent.
The access token that you get back from the JWT grant flow lasts an hour. So you'll need to repeat the JWT call if you need to make another API call after that. Please do not create a new JWT grant for each API call! Cache the access token.
Question #2: The SDK seems to be overkill. I've written against REST APIs before and I'm comfortable working in that world. So, SDK vs. manually writing what I need. Advice? And whichever choice is preferred, where do I start?
Half of the developers who use the DocuSign eSignature REST API call the API directly. So we're happy for you to do that if you prefer.
Create the request object as a PHP associative array, convert it to JSON and then call the API using your favorite HTTPS request library.
If you have a problem doing so, open a new StackOverflow question.

Related

Can you get a short-lived OAuth 2.0 access token for Firebase in PHP?

i am currently working on a Project with Firebase and i am trying to Implement the Firebase Cloud messaging service. I manage to make it work with a combination of PHP and Javascript (Javascript sends a Requiest to the server, where php makes a call to the Firebase API to send out a Notification).
The problem here is, that the code i use is for the old version, so its not using the HTTP v1.
When i looked at the docs on how to upgrade to the new version, i found out you need a short-lived OAuth 2.0 access token.
Thing is, the docs only show how you can get it via node.js, java, python, c# and go.
So my question is, is there a way to get the short-lived OAuth 2.0 access token with php or do i have to use something like node.js for it?
I'm not sure I fully understand your requirements, but if you want to send FCM notification from a PHP backend, I'd suggest checking out this (unofficial) Admin SDK for PHP (Disclaimer: I'm the creator of that library)
In its current state, you would need a Firebase Service Account (with Admin access) to be able to send notifications with it, but I'm currently working on a feature that will allow you to retrieve an OAuth access token for a given user (https://github.com/kreait/firebase-php/pull/390) in case you really need this.
I'd like to invite you to join https://discord.gg/nbgVfty (the Discord-Community around the PHP Admin SDK) to discuss your use case and process further.
Even if the SDK is not for you, looking through the code might could give you some ideas...
An alternative could be to use the Google PHP Api Client Services library, in which you can find a FirebaseCloudMessaging service.
I hope this helps!

Using RingCentral PHP SDK to build app that uses Authorization Code flow and subscribes to presence events

I am trying to build a web app that is using RingCentral PHP SDK to subscribe to presence events. The application will be using Authorization Code flow. I am getting the access token but have no idea how to use this token with SDK and Platform objects. It looks like SDK is geared towards using Password flow.
Should I use plain curl to invoke POST /restapi/v1.0/subscription HTTP/1.1 passing access token in Authorization Header? Or there are ways to use RingCentral SDK objects for it? Am I missing something?
If you could provide a little more information about your use-case, and how you're implementing the code, I can provide greater detail.
To create a subscription using the PHP SDK, here is the demo code contained within the RingCentral PHP SDK repository on Github
TL;DR
I see two questions being asked:
Does the RingCentral PHP SDK support Authorization Flow (3-Legged OAuth), because currently it appears the SDK is focused only upon the Password Flow?
Authorization Flow is the best-practice for building multi-tenant applications since it removes the security risk of your application storing usernames and passwords which are associated with RingCentral accounts. The RingCentral PHP SDK supports Authorization Flow and Password Flow authentication types. Once your PHP SDK instance has a valid access_token then it can create a subscription quite easily.
We can see in the PHP SDK code on Github within src/Platform.php that constant AUTHORIZE_ENDPOINT is supported as a returnable value from a request to authUrl().
You can see in Grokify's RingCentral OAuth PHP Example that Authorization Flow is supported by the PHP SDK.
Once your SDK instance has a valid access_token, it will use that token in the Authorization header when you createSubscription(), addingListeners(), and register() as seen in this PHP demo code to create a subscription
How do I create a RingCentral Subscription using with the PHP SDK (does the SDK have objects associated with it I can use)?
There are several ways you can go about using the RingCentral SDK(s). I've provided a link to the PHP Demo on creating a subscription in the above TL;DR.
Since you are working with the RingCentral PHP SDK, then you are restricted to server-side implementations as PHP is a server-side only language.
How you choose to implement your subscription is entirely dependent upon your application's use-case needs and your architectural requirements. Since you have indicated you are using Authorization Flow, that leads me to believe you are building a multi-tenant, web-based application integration. Since you said you are getting an access_token, I am guessing you've called the Platform.login() and passed it the code value you receive from the 3-Legged auth request to /restapi/oauth/authorize and received in the redirect. I'm not sure if you're doing all this from the client or server, but I'm assuming the server.
You would need to associate the session to the SDK instance and subscription on the server-side. This means you will have to manage multiple SDK, and Subscription instances for each client-side session. You might also need to implement WebSockets or Long-Polling so you can achieve the near real-time event updates that Subscriptions enable. So while, yes the RingCentral PHP SDK can be used with Authorization Flow, I personally would recommend against using it for any end-user, client-side, multi-tenant application development (unless you have properly prepared for mapping the sessions to the SDK/Subscription instances as I described earlier.
If you do not want to manage all of that on your server-side, you could use the RingCentral JS SDK on the client-side of your PHP application, but this might get a little messy and require some re-architecting of your solution depending upon how you have things built. Of course, this approach has a data-volatile aspect depending upon what you want to do with the data you obtain from the subscription and if you need it to persist between sessions (once again depends upon your use case).

Accessing google docs via a program in php and not in a browser

I want to access, view, modify Google docs but via a program written in php.
I would prefer to use API protocol as it can be used by any language.
But apparently the API requires me to be signed in in a browser. Now if I want to make a server side script that apparently wont be running in a browser, how can I do that?
I didnt found any username/password/auth giving thing that returns me some token and the API can use that token.
https://developers.google.com/google-apps/spreadsheets/#changing_contents_of_a_cell
google would not know who sent the second request if it does not has the access token or some way to prove that it logged in a minut a go. in my case: the program (lets say php server)
I guess this would not help https://developers.google.com/google-apps/spreadsheets/#authorizing_requests for https://developers.google.com/google-apps/spreadsheets/#changing_contents_of_a_cell as the later has no access token option.
You should authenticate your clients with OAuth2 and then store the tokens in db: https://developers.google.com/drive/web/auth/web-server
Also there's a client library available from Google: https://developers.google.com/api-client-library/php/
Edit: As you said it's about the spreadsheet API I'm linkin directly to the spreadsheet API authentication documentation: https://developers.google.com/google-apps/spreadsheets/#authorizing_requests_with_oauth_20 seems they support OAuth2 too.
Thanks to all but I found something working exactly as required.
http://framework.zend.com/manual/1.12/en/zend.gdata.html

Dropbox API without user action, standalone app

I'm trying to develop a PHP script to synchronize files with a Dropbox folder that I own.
I'm trying to connect using the Core API and OAuth 2, and it seems that a user needs to get an authorization code from an approval page, but my script needs to be stand alone without any user interaction.
My question is : is it possible ?
I didn't find anything to the Dropbox API documentation to achieve this.
Thanks in advance for any link, help or alternatives.
As #dev-null-dweller said in a comment, you certainly need to authorize the app once, but you can just store the token and keep reusing it.
You might want to use my app http://dbxoauth2.site44.com/ to get an OAuth token for yourself and then just hardcode it in your script.

github API v3 - acquiring access token through CURL

I've been puzzling through the github API docs (v3) and I'm kind of stumped. For the initial step - the acquisition of the access token - it appears that the only way to do it within a web app is to rely on a callback URL, which gets posted a temporary code. That's then used in subsequent queries to their API.
Does anyone know if this can all be done in a single step, e.g. cURL - i.e. within a single block of code in one page? Passing off control flow to a different URL causes innumerable problems for my particular scenario.
Thanks! :)
This is the nature of OAuth. You could you try to use the basic authentication method, but if that doesn't fit your needs, then PHP has an OAuth library that should make authentication pretty painless. There are also a few PHP wrappers out there for the Github API, e.g. php-github-api.

Categories