Handling Authentication through streamlit webapp

Hi All,

I’ve gotten my webapp to the point where it can now be deployed. But running into another problem, which is getting the authenticated user.

I was following the tutorial here which builds a website in Vuetify, has anyone done this in streamlit?

Creating Your Own App | Speckle Docs

Not quite sure where to go from here so any pointers would be great!!

1 Like

Hey @shuzmm ,

@Wassim_Jabi made a streamlit app and afaik figured the authentication part. You can sneak peek into his code. I think below is how he figured it out.

2 Likes

Hi ping me if you need help authenticating to Speckle from Streamlit.

2 Likes

Amazing stuff!! thanks for the assist @Wassim_Jabi will send you a message

2 Likes

Hi everyone;

I´ve been trying to deply a simple streamlit app but I´m getting this authentication error in the streamlit platform:

2023-01-16 12:40:00.598 >>> {"query": "query Server {\n  serverInfo {\n    version\n  }\n}"}
2023-01-16 12:40:01.118 <<< {"data":{"serverInfo":{"version":"2.11.4"}}}
2023-01-16 12:40:01.121 >>> {"query": "query Server {\n  serverInfo {\n    version\n  }\n}"}
2023-01-16 12:40:01.416 <<< {"data":{"serverInfo":{"version":"2.11.4"}}}
2023-01-16 12:40:01.419 >>> {"query": "query User($id: String) {\n  user(id: $id) {\n    id\n    email\n    name\n    bio\n    company\n    avatar\n    verified\n    profiles\n    role\n  }\n}", "variables": {"id": null}}
2023-01-16 12:40:01.757 <<< {"errors":[{"message":"You do not have the required privileges.","locations":[{"line":2,"column":3}],"path":["user"],"extensions":{"code":"FORBIDDEN"}}],"data":{"user":null}}
2023-01-16 12:40:01.761 >>> {"query": "query User($stream_limit: Int!) {\n  user {\n    id\n    bio\n    name\n    email\n    avatar\n    company\n    verified\n    profiles\n    role\n    streams(limit: $stream_limit) {\n      totalCount\n      cursor\n      items {\n        id\n        name\n        role\n        isPublic\n        createdAt\n        updatedAt\n        description\n        commentCount\n        favoritesCount\n        collaborators {\n          id\n          name\n          role\n        }\n      }\n    }\n  }\n}", "variables": {"stream_limit": 10}}
2023-01-16 12:40:02.102 <<< {"errors":[{"message":"You do not have the required privileges.","locations":[{"line":2,"column":3}],"path":["user"],"extensions":{"code":"FORBIDDEN"}}],"data":{"user":null}}

If anyone has some inputs I´ll be be thankful

Best.
Tomás

Is stream sharing turned on? Or if not, are you passing a user token?

Hi!
The stream is public and I am passing a user token.

When I launch it from the local host, it works without problem. is when I am deploying it on streamlit that is giving me this error.

1 Like

How are you authenticating? Can you share the repo?

I notice that you have a health check error on your deployed app that is pointing to localhost:8501 still. Not sure if it would be the cause of the issue. Maybe you have to update some value somewhere?

Hi!
I´m authenticating with a token.
here you have the repo.

Thanks

Finally I generated a new token and it granted me access. Now a new problem, the Iframe doesn´t show up .

1 Like

Hey @tomasmena

First things first. You really shouldn’t have your token shared in a public repository, now I (or anyone else a bit more malevolent) can have access to your data. If you want to keep the authentication method wit a token I suggest you use an environment variable to store and retrieve the auth token.

I tried to clone your repo and run the app, but it failed for me too, because the baked in string token is invalid.

The reason why it works locally, is because specklepy falls back to accounts available on your machine.

3 Likes

Good, now revoke it and use environment variables instead of inlining in the public code. Does streamlit support that?

So, the next step, is what is the developer console reporting? Is the viewer present in the DOM?

1 Like

afaik, streamlit does support environment variable.

1 Like

The viewer is present on the DOM

I can see it hasn’t loaded, what does the console log report?

5.1ebf0425.chunk.js:2 Mixed Content: The page at 'https://publicmachinery-winter-garden-main-c6ibzw.streamlit.app/' was loaded over HTTPS, but requested an insecure frame 'http://speckle.xyz/embed?stream=8dd22c09e4&commit=f42a6e31b6&autoload=true'. This request has been blocked; the content must be served over HTTPS.

If you add an s to http for the embed URL?

https://speckle.xyz/embed?stream=8dd22c09e4&commit=f42a6e31b6

1 Like

It Works!!! thanks a lot for everyone’s patience !
@gjedlicska thanks for the observation… Really important. !

3 Likes

Hey @tomasmena ,
quick question: why did you authenticate? As far as I see, there is no need for authentication in your case. It is a simple embed viewer, isn’t it?

1 Like