#Samsung

1 messages ยท Page 1 of 1 (latest)

iron oak
#

I think you can't really integrate that easily

#

As you need a custom redirect URI

#

(I think)

lucid mason
#

yes

#

that's what I wrote

#

๐Ÿ™‚

iron oak
#

Do you know postman?

lucid mason
#

yes

#

a bit...

#

I was thinking to NGINX

#

to transform "samsungfood" to "HTTP"

#

in my windows host file I already added

#

127.0.0.1 samsung_auth

iron oak
#

Like, I think you can just forget making this seamless

lucid mason
#

but the scheme is not HTTP

iron oak
#

But in postman you can put in a different redirect uri

mild sapphire
#

you have a link to this fridge? I'm genuinely curious about a smart fridge

iron oak
#

so you can just receive a token and refresh token

#

and maybe if you can figure out the refresh token part you're done

lucid mason
#

I have all the API calls

#

from the APP

#

I scraped them all

#

I am planning to write a custom component

#

and publish it

iron oak
#

I think you can use postman to get the accesstoken and refresh token

lucid mason
#

my idea is to sync Grocy and Samsung Fridge food list

iron oak
#

and then put that into the integration and work with it

#

But does smartthings help any in this case?

lucid mason
#

postman via python?

#

no no

#

smartthing no...

#

and btw Whisk closed the developer program

#

since when it was acquired by Samsung

#

so you cannot ask a client_id/client_secret

#

anymore

#

which you could do before...

#

so I was planning to use the client_id of the app

iron oak
#

hmm

lucid mason
#

(btw the app doesn't use the client_secret

#

)

#

@iron oak are you an expert of OAUTH ?

iron oak
#

I have some integrations in HA that use Oauth

#

Youtube/withings/spotify

lucid mason
#

some you made?

iron oak
#

I only made youtube, but I maintain the other 2

lucid mason
#

fantastic

#

would you mind helping me with this one?

#

we could write a custom component together maybe

iron oak
#

Well, you still have the problem that you can't edit your redirect url

lucid mason
#

yes...

iron oak
#

So that makes me believe that you can't do the login part in the integration

lucid mason
#

but maybe you can help me fixing it

#

I scraped the bearer token

#

made test with APIs

#

and I'm able to sync Grocy and Samsung Food

#

so when I add/remove a food from Grocy

iron oak
lucid mason
#

my Fridge sees the difference

#

I saw the token in clear in API call from the APP

#

and I used the same token to make some test on the Food APIs

#

The url

#

sends back the authorization code to samsungfood://samsung_auth?code=5lYXXXXXXXXXXXXXXXXXXXXXXXXX

#

state=samsung_oauth

#

and then the APP calls the API

#

using this code (and something else... I still dunno what)

#

in the gRPC format

iron oak
#

Yes this is ouath

#

but that isn't refresh yet

lucid mason
#

it uses Goofle Remote Procedure Call

#

Refresh is documented here

#

Whisk doc page is still available

#

before Samsung will destroy it...

#

I also tried to open a Family Hub Developer on Samsung website

#

but they never accepted my request

iron oak
lucid mason
#

yes yes

iron oak
#

oh apparently you do need a client secret

lucid mason
#

I saw both in the response

#

no no

#

not needed

iron oak
#

https://login.whisk.com/oauth/v2/token +
?client_id=${WHISK_CLIENT_ID} +
&grant_type=refresh_token +
&refresh_token=${user.refresh} +
&client_secret=${WHISK_SECRET}

lucid mason
#

the APP doesn't use a client secret

#

yes true... the doc says this

#

but you can use challenge_code

#

skipping the client_secret

iron oak
#

I think without these client credentials its kinda hard to create an integration out of it

lucid mason
#

I also have the client_id

#

I just need to retrieve the auth code sent to redirect URI

#

if you have time, maybe we could work together

iron oak
#

I currently already have a lot on my plate (and I keep distracting myself oops)

lucid mason
#

๐Ÿ˜ฆ

#

maybe you can give me some hints

iron oak
#

So like, I am available for some questions, but I don't have time to pick up a whole project

lucid mason
#

I could do the entire job

#

but I would need some guidance

#

it's 2 days I'm trying to study OAUTH

#

I'm new to it

iron oak
#

one thing is clear, without client id and secret or developer account you can't login in the integration itself

#

that's a nogo

lucid mason
#

but I could if I would be able to redirect samsungfood:\ to localhost

#

wouldn't I ?

iron oak
#

you can't

lucid mason
#

why not? maybe a proxy like NGINX ?

iron oak
#

You can only intercept that with a custom browser

#

Like, your browser will just try to go to samsungfood://

#

you can't host something there

#

apps have something in them that will catch these urls and opens them in the respective app

#

So unless you are using a browser that catches these urls, you can't do it

lucid mason
#

in python there is no such custom browser?

iron oak
#

No

#

This isn't in python

lucid mason
#

I also did the code to simulate login/password of Samsung account using Chromedriver

iron oak
#

oh well

#

you can use stuff like selenium or beautifulsoup

#

but that's a baaaaad approach

#

trust me

lucid mason
#

so I can automatically login into samsung account

iron oak
#

they change one thing in their page structure and you are fucked

lucid mason
#

I imagine

#

and I know

#

but I'm looking for something to make it work

#

it would be a nice automation to sync the fridge with Grocy

#

do you know Grocy?

iron oak
#

ye

lucid mason
#

you can use barcode scan

#

and it's fantastic

iron oak
#

I like the idea but its difficult to set up

lucid mason
#

with Fridge, you need to manually insert them...

iron oak
#

I mean

#

honestly

lucid mason
#

difficult... not impossible...

#

๐Ÿ˜‰

iron oak
#

just get an ESPHome with scanner ๐Ÿ˜‚

lucid mason
#

you have the Android App for Grocy

#

and Grocy is integrated in HA

#

why do I need an ESP Home with scanner?

#

๐Ÿ˜„

iron oak
#

to replace the smart fridge ๐Ÿ˜›

lucid mason
#

ahahaha the Fridge is nice

#

it shows in beautiful way when food is overdue

#

and the next food to be consumed

#

so I like the Family Hub UI

#

but the backend is very bad

#

๐Ÿ˜„

#

so with beautiful soap and selenium/chromedriver I could get the answer sent to samsungfood:// ^

#

?

#

in chromedrive I see the webpage HTML as result of the authentication

iron oak
#

I think so, but that would be the least of my worries right now

lucid mason
#

that contains a form

#

with two hidden inputs

#

code and state

#

the code is a JSON

#

that contains a code tag

iron oak
#

As in yes, you now have the authentication code, now what

lucid mason
#

but this is not the real auth code

iron oak
#

you still need to connect with gRPC, can you do that sucessful?

lucid mason
#

why?

iron oak
#

The token you get back, how long does it life?

lucid mason
#

what's the challenge there?

iron oak
#

Did you try it?

lucid mason
#

not yet

iron oak
#

Then why do you expect that it works

#

Like, what I am saying is, try to test every piece

lucid mason
#

I'm new to it ๐Ÿ™‚ told you

iron oak
#

before diving into it and finding out that it doesn't work

#

You rather want that 5 hours in, than 5 days

lucid mason
#

but with HTTP toolkit

#

I saw the same auth code sent to samsung food

#

to be used in the gRPC call

#

and gRPC call doesn't have a redirect URI

iron oak
#

yes, you need that to get a token

lucid mason
#

and gRPC gives you the bearer token and the refresh token

iron oak
#

yes

#

you have to trade in the authorization code for those 2

lucid mason
#

I think the token lasts for many days

#

true

#

I understood it

#

already

#

the only challenge I have with gRPC

#

is that the request body seems to be encrypted

#

there are some strange characters

iron oak
#

that might be a problem

lucid mason
#

but the auth code is in clear

#

same string sent to samsungfood

#

there is an it-IT string

#

and some strange characters

#

any hint you can give me?

#

I'm kinda blocked...

iron oak
#

Not really

#

You have to figure out what it means

#

Like, maybe it's just some gRPC thing

#

I know what it is and what it does, but havent worked with it

#

it's not encrypted at least, otherwise you wouldn't have seen the cleartext vars

lucid mason
#

yes it's not encrypted

#

I mean any hint to redirect samsungfood to localhost?

iron oak
#

you can't

lucid mason
#

๐Ÿ˜ฆ

iron oak
#

like with a google driver thing you can detect that you are being forwarded to such link and act on it

#

but you can't handle it in a normal browser

lucid mason
#

but I could handle it with chromedriver?

#

what kind of google driver?

#

what a pity... I'm very close to it... I tested all the APIs...

iron oak
iron oak
lucid mason
#

I dunno how to google it ๐Ÿ˜ฆ

iron oak
lucid mason
#

yes... but I tested add food, edit food, consume food etc...

#

I can see Grocy list on my Fridge

#

updated

iron oak
lucid mason
#

I know this...

#

why do you think gRPC is so complex?

iron oak
#

I don't, but currently that's the biggest question mark

#

It can make or break your whole project

lucid mason
#

even if I make the gRPC... and I dunno how to get the auth code...

iron oak
#

Yes I could tell you that you need to Google for "webscraping", but then you're going to focus on that

#

And then you may have the full login flow working, you can receive an Auth code

#

But if you can't trade that Auth code for a bearer token, you're still nowhere

lucid mason
#

maybe I was not clear... I can use already selenium to fill in the form data

#

to put my username and password

#

and I reach the signIncomplete page

iron oak
#

And then

lucid mason
#

<body onload="document.frm.submit();">
<form name="frm" method="POST" action="https://login.whisk.com/oauth/v2/callbacks/samsung">

<input type="hidden" name="state" value="STATE VALUE HERE..." />




<input type="hidden" name="code" value="A JASON HERE....." />

</form>
</body>

#

I get this in my chromedrive response

#

there is a state and a code

#

code is a JSON

#

that contains client_id

#

code

#

code_expires_in

iron oak
#

You need to do a request to that URL with the state and code

lucid mason
#

{"client_id":"XXXX","code":"XXXXXX","code_expires_in":"300","scope":"3RD_PARTY","inputEmailID":"XXXXX","api_server_url":"eu-auth2.samsungosp.com","auth_server_url":"eu-auth2.samsungosp.com","close":true,"closedAction":"signInSuccess"}

#

the app makes a request to

#

with state and code

iron oak
#

Yes

lucid mason
#

and gets in the response

#

samsungfood://samsung_auth?code=XXXX&state=samsung_oauth

#

this is the "location:"

#

but after the login executed

#

if I use the same state to make this API code

#

it says... state already used

#

I hope I explained it properly...

iron oak
#

Yes

#

You can do that request and you get redirected to this page, you can view that

#

I'm sure of that

lucid mason
#

yes but I don't get the code in this way...

iron oak
#

Like I'm 100% sure that if you do a request to that endpoint and you get redirected to that Samsungfood page, you can read that URL from the client

lucid mason
#

to which one?

#

callback?

iron oak
#

That Samsungfood:// URL you get redirected to

lucid mason
#

sorry I don't understand...

#

I don't see samsungfood in my chromedriver browser

iron oak
#

You get redirected to Samsungfood:// after successful Auth right?

#

After doing that state code call?

lucid mason
#

no no

#

let me recap

#
  1. I fill in username and password with python script
#

in this page, I see a form

#

with two input hidden

#

state and code

#

if I scrape the app with HTTPtoolkit

#

I see that the same state "a string" and code "a json" are sent to

#

if I make this call after the point 4

#

using state and code

#

it says "state already used"

#

{
"code": "oauth.accessDenied",
"description": "States has already been used"
}

#

is this clear now?

iron oak
#

This is because the state is already used by the app

#

I think

lucid mason
#

the state is different

#

every call I make

iron oak
lucid mason
#

I don't understand how to get the auth code then...

#

I don't see the redirect url

#

to samsungfood

#

in chromedriver

#

or maybe it's too quick... I don't see it in the address bar

#

If I click back on the chromedriver browser

#

with the state in the URL

#

I'm lost ๐Ÿ˜ฆ

#

maybe this...

#

I got the code!!!!!!!!!!!!!

#

for request in driver.requests:
if request.response:
for k in request.response.headers:
print(k + " " + request.response.headers[k])

#

I can print the location id

#

of the header

#

that contains the code!!!!

lucid mason
#

@iron oak what is the code challenge I should use?

#

I'm referring to this

#

Whisk is compatible with Aaron Parecki

#

I made it ๐Ÿ™‚

#

I'm now able to generate the access token and the refresh token

#

expires_in 86400

iron oak
#

nice

lucid mason
#

Integration is finally ready and working!!

#

Now my Grocy is in synch with Family Hub Fridge