Sample of token based authorization

I am planning to create a binding for Husqvarna AutoMover as my second binding.
I will look at https://github.com/chrisz/pyhusmow
It seems that it uses Token based authorization.
Is there any other binding that uses this where i can look.
I am still struggling with learning Java :slight_smile:

/Mike

Do you know which protocol? OAuth2? or something custom?

Seems in pyton that you post username and password and receive token informattion.

    def login(self, login, password):
        response = self.session.post(self._API_IM + 'token',
                                     headers=self._HEADERS,
                                     json={
                                         "data": {
                                             "attributes": {
                                                 "password": password,
                                                 "username": login
                                             },
                                             "type": "token"
                                         }
                                     })

        response.raise_for_status()
        self.logger.info('Logged in successfully')

        json = response.json()
        self.set_token(json["data"]["id"], json["data"]["attributes"]["provider"])
        return json["data"]["attributes"]["expires_in"]

/mike

I don’t know what protocol that is. It looks custom and simple. There is probably no standard support out-of-the-box for it. So you need to implement something yourself. Using HttpUtil you should be able to get the token and store it in some cache. For some inspiration look this earlier Spotify api implementation. It’s based on OAuth2. The earlier implementation had OAuth2 implemented, but current PR uses the OAuth2 implementation part of openHAB. To give you an example here is the token cache handling:

Just browser there to other files too and copy what you can use. Hope this helps somewhat.

Thanks now i have somewhere to start.

/Mike

Hello,

Do you have a test version already?

I will be happy to test it?

Not yet still struggling with token based login in java.

/mike

Hi Michael,

Do you know that there is an open API for Husqvarna Automower?

Regards
Martin

I Know but was hoping this should happen :slight_smile:

/Mike

I started but with slow progress. Then I realized the API does not provide position coordianes (which is possible via the husmov solution). Means, atm I do not continue with the binding. But I hope the API will be expanded and will provide more data in the future. Until then I decided to live with the current solution.
mower

@HaKuNa Can you share the source?

/Mike