I am trying to develop a simple Instagram feed that grabs the latest four posts and then embeds permalinks into a modal but I having issues trying to find a way to store a long term token. I am working with the new Basic Instagram API and It requires you to do a couple exchanges of authorization codes for short term codes and then long term codes. I have code using the org.apache.http.client.HttpClient org.apache.http.client.methods.HttpGet org.apache.http.client.methods.HttpPost methods to get responses and do the exchange of tokens etc. That works great but I just don't know where to store it so it can be used across all sites. Ie I don't want to have to get a new long term token each time for each site and I don't know if Instagram supports that.
My idea is to have the authors be able to supply the client app id, secret code, intial authcode, and redirect uri either on the component or cloud service config and then my code would grab the short term token and long term token, and store those somewhere.
I've looked at the cloud service configs which seem ok but they are jsp based and am having trouble including a service in them to make the calls out and don't really have a clue how I would set the token in a property on the config after I've gotten the value. I've tried using sling.getService(service.class) but the object is null. I know in models I can use the "@inject" and "@reference" but that doesn't help with the cloud config as they are jsp.
Another concern with the cloud config is making sure authors include the cloud config in the page properties. I guess I could create a template for it but seems like a lot of work for just a feed. I am also unsure how cloud service configs get replicated? They seem like content and I am not sure how I would attach a component to the cloud config. I know there is a reference to components with the cloudconfig but that seems like more a way to embed scripts into headers.
The next thing I tried was to create a ogsi config with the r6/r7 annotations which seem fine but even if I supply configurations for the account there, I don't seem to have a way to dynamically store the long term token once I've received it. I looked at using the configurationadmin but when I use it with the r6/r7 and try and get by pid, if no values are configured it will create a new osgi config. If have one value set it seems to return the values. Both times it seems to bind it to the model. I've been referring to http://www.nateyolles.com/blog/2015/10/updating-osgi-configurations-in-aem-and-sling but I know that uses the felix scr stuff which is now deprecated. Do I have to have the get and set methods in my service to get this working correctly? Also is this the proper way to do this? The article is quite dated and there is no reference to configuration admin in any newer stuff.
I am an ok java developer and just getting my sea legs back sort of speak; I just want to know am I think about this incorrectly. Is there a better way to do this? I've seen some stuff that relates to tokens surrounding login but that seems overly complicated for such a simple use case. My main questions is what would be the correct and recommended approach for this? Ie storing a long term token and persisting across author and publish so once I have the token I can use it however I want.
I know I will have an issue down the road keeping the token refreshed but I think I could do some type of scheduled service once I have the token.
Thanks,
Landon Cunningham