• Resolved blastframe

    (@blastframe)


    Hello,
    Similar to this user’s request, I was hoping to find an example of your plugin using Python so a user can authenticate my software on their computer (unless there’s a safer way to do this). I’m not sure which address to get or how to find if a license is valid. I looked for docs here and here, but didn’t see any. I am using Python’s Requests library.

    
    import requests
    
    def main():
        r = requests.get('https://api.github.com/user', auth=('username', 'password'))
        print r.status_code
        print r.headers['content-type']
        print r.encoding
        print r.text
        print r.json()
    
    if __name__=='__main__':
        main()

    Thank you!

    • This topic was modified 4 years, 9 months ago by blastframe.
Viewing 12 replies - 1 through 12 (of 12 total)
  • Hello @blastframe

    Thank you for your message and for using my plugin.

    I’m sorry for the late reply. I honestly don’t have any Python knowledge myself, so i can’t help with this. However, if you were to create a Python library which helps utilize the REST API, I will add it to my website (with proper credit of course):

    https://www.licensemanager.at/docs/rest-api/libraries/

    I am currently looking for people willing to share their own libraries, and Python definitely is on the list.

    Thread Starter blastframe

    (@blastframe)

    Hi,
    I would be happy to share if I develop such a library. Could you please direct me to a simple GET request in any language (PHP perhaps?) and I will do my best to replicate it in Python?

    I’m not sure what the REST URL would be for my site with your plugin installed.

    Thank you!

    @blastframe

    Take a look at the REST API docs here: https://www.licensemanager.at/docs/rest-api/

    An example request URL would be:

    (GET) https://www.example.com/wp-json/lmfwc/v2/licenses

    This would list all the licenses from the database. If you need anything else let me know.

    Thread Starter blastframe

    (@blastframe)

    That’s excellent, I’ll give it a try! If I get it working I’ll post the Python code. Thank you, Drazen.

    @blastframe

    Awesome, thanks! I’m sure it will be a tremendous help to others ??

    Once you’re done, you can send the library to [email protected].

    PS: To give you proper credit on my website I will also need your full name (or nickname, whatever you’re more comfortable with) + your website to which to link to.

    Hi everyone,

    If you want to validate a key using this tool in Python, use the following method.

    import requests

    def verify_account_key(account_key_to_check):
    
        yourwebsite = "" #for example, niftynicktools.com
        consumer_key = "" #the consumer_key given to you when you establish your API with License Manager
        consumer_secret = "" #the consumer_secret given to you when you establish your API with License Manager
        url = "https://" + yourwebsite + "/wp-json/lmfwc/v2/licenses/validate/" + account_key_to_check + "?consumer_key=" + \
              consumer_key + "&consumer_secret=" + consumer_secret
    
        verification_json = requests.get(url, headers={"User-Agent": "XY"}).json()
    
        try:
            if verification_json['success'] == True:
                return True
        except:
            return False
    
    #Try some keys
    verify_account_key("")
    verify_account_key("")
    • This reply was modified 4 years, 4 months ago by processzip.
    mikeramsey869

    (@mikeramsey869)

    Nice snippet @processzip I wish i had seen that before i made my wrapper lol.

    I added your snippet with attribution in my pylicensemanager which is opensource.

    The the code has an option to generate uuid and to send that back in json response too. We just need the plugin to accept this by default and consider it valid on the validate or activate vs invalid if its activating/validating on the same uuid vs failing saying already registered.

    feel free to submit pull requests
    https://gitlab.com/mikeramsey/pylicensemanager
    https://pypi.org/project/pylicensemanager/

    @drazenbebic Where do i put the filters and hooks for this?
    https://www.licensemanager.at/docs/tutorials-how-to/additional-rest-api-validation/
    https://www.licensemanager.at/docs/tutorials-how-to/modifying-the-rest-api-response/

    Also is there any documentation for the upcoming v3 api? If so please let me know would like to update the library to fully support all methods and would be nice if we can add public key signed messages which can be verified client side to confirm the response is coming from our url and signed by our public key.

    willwinter

    (@willwinter)

    Ive tried to setup the plugin and use the python requests script with the API but none of it seems to be working and i keep getting ‘There has been a critical error with your website’ when i manually use the links that im requesting using the API.

    https://i.snipboard.io/5wcNZS.jpg

    mikeramsey869

    (@mikeramsey869)

    can you provide the the scripts you use with the api keys removed and example to shown. If the wordpress is showing a 500 error its possible the PHP is wrong though vs the api.

    Did you add stuff into your child theme’s functions.php? If so first off your going to want to probably comment out or remove it and make sure the wordpress is not showing errors when curling the domain api.

    Heres minimal example Python script. You can load in like Pycharm and run easily to test retrieving a single license key.

    This should work assuming you have created a License Key and setup your rest API keys and their active and valid.

    Edit the edit section with your information as applicable then run it
    https://pastebin.com/pihY7Ry4

    Should look something like the below when valid key is run.

    View post on imgur.com

    Once you have confirmed the API is working then I recommend going back and trying to work with the fancy filters. I got hung up on trying to make it all work before gradually working up to what I wanted.

    Only thing really left is getting it to save the uuid and nice_name from the device into the license meta. The Validate does not check if expired inactive so best option I found was to validate based off the license key full details from the retrieve license details base and add my logic from there.

    Hopefully that helps you @willwinter

    willwinter

    (@willwinter)

    @mikeramsey869 I was using the script above mentioned by @processzip but ive also just tried yours and for some reason im getting the same result with the ‘critical error’ message, all ive done is install my theme and customise it and its necessary plugins, installed the license manager plugin, and created a testkey and some API credentials but it doesnt want to work, ive also tried changing the theme and disabling other plugins to see if there is some conflict but it still doesnt want to work, the only thing ive done is edit the wp-config to add define(‘LMFWC_PLUGIN_SECRET’, ‘secret.txt’); and define(‘LMFWC_PLUGIN_SECRET’, ‘defuse.txt’); aswell as a few lines to turn on debugging to see if i can see what is going wrong but that didnt work either. Im not having much luck with this plugin unfortunately, im going to keep trying to fix it but if you can give any help that would be great. am i right in how i setup the plugin; fresh install of wordpress, installed my theme, installed license manager, created a key, created api keys and then im trying to run your script using my creds and website. theres no further setting up with permalinks or anything else that needs configuring?

    willwinter

    (@willwinter)

    I then get emails through of a critical error/technical issue such as this: https://i.snipboard.io/QYRf6B.jpg

    willwinter

    (@willwinter)

    Ive spoken to EasyWP support and let them see about the issue they had some technicians at it for an hour and resulted in this: https://i.snipboard.io/67tBfu.jpg

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Python REST API Example’ is closed to new replies.