puter
puter copied to clipboard
C# Wrapper for Puter
C# Wrapper Library Idea for Puter (PuterSharp, no github page yet)
I've been working on a C# Wrapper (or basically a package) for Puter.js in order for C# Developers to be able to access mainly the AI services that come with Puter since they are free to use and we are lacking in the C# Department of AI.
No lie, I've been working more than 30 hours straight (4 days total with breaks) trying to figure out how I can make it work and the issue is the pop-up for authentication. The problem is, the way I made the library access puter's AI is even more unstable. It's meant to all be automatic, and for practice I tried to automate the authentication by automatically opening the https://puter.com/embedded_in_popup=true&request_auth=true page automatically without clicking the Continue button. Now, obviously, this doesn't sound very ethical since it's meant to not only authenticate the user but also remind him of the terms of Puter. What I was thinking is that I could just explicitly mention and link the terms everywhere around the library including when it gets initialized in the console that "by using this library, you are agreeing to the Puter.js terms of service" and I'd link the terms etc.
Now I've gone pretty far with the library, but the only issues are:
- Sometimes puter would authenticate you automatically, and sometimes it'd ask for a Login (creates uncertainty and it's not a good idea if I want to publish a library based off of it)
- The pop-up coming from puter
window.open(puter.defaultGUIOrigin+"/?embedded_in_popup=true&request_auth=true"+(window.crossOriginIsolated?"&cross_origin_isolated=true":""),"Puter","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=600, height=400, top="+t+", left="+e)})is literally IMPOSSIBLE to make invisible without the code in the auth page not working.
It's been very very hard 4 days of trying to get this to work, and I don't want to continue in an unethical manner either so I decided to make this issue. Hopefully, I could get some help with this. I just want to figure out a way to not get a pop-up!
People who use this library for commercial apps obviously wouldn't want to flash their users with a random pop-up that's unrelated to the app they're using about something they don't understand. I hope you understand what I mean.
I respect this project a lot and I'm obsessed with it and I urgently request help and assistance with it, and perhaps a solution to the issue I'm facing. Thank you.
I hope to see a response soon I'm really passionate about making this work I also want to use this for my own projects! Please let me know if you can provide any help with this!!
So you want a third-party app to use a new guest account on Puter to provide free AI services to a user that's not using Puter, right? We don't support that. The user needs to knowingly login to Puter.
Well my aim is to allow people to use your services for their commercial apps and obviously people using these apps don't want to get a pop-up every time. Anyways, since this is how it's gonna be I guess I'll just use what I can work with. Thanks anyways.
@voidZiAD Your application state can keep the token, can't it? That would be the same way you'd handle this situation with any other service.
Does it only need to authenticate once?
I'm not very familiar with the way it works. Doesn't it expire after some time? Also I'm not sure how I can even retrieve the token. I'm using a Chromium library and usually it DOES save the data needed and It doesn't need to authenticate again until sometime (at least from my experience). However, it may be the case that it doesn't expire. Depends on how your system works or if the library has a problem. I don't think it's the library though it's well known.
I will definitely test it and see overtime since the way I'm developing it rn has the browser data get deleted every time the library is used. Also if all this sounds confusing, basically I'm using a browser library to execute your js code for puter in C# and handling everything from there so people don't have to when they use puter in C#. Thank you for the idea though, I'll see if I can do something and make it work that way.
Hi @voidZiAD,
To answer your questions about token persistence:
-
Yes, authentication only needs to happen once per user session. After the initial authentication, the token should be saved and reused.
-
Token expiration: Looking at the code, Puter uses JWT tokens that don't have a built-in expiration for regular session tokens (unlike some API tokens that do expire). The tokens remain valid until explicitly revoked or the user signs out. This is subject to change; the UI will rotate tokens and we will provide a different mechanism for persisting tokens.
-
Token retrieval: After the user authenticates through the popup, you should be able to retrieve the token from the message event that's sent back to the window. In the Auth.js module, line 65 shows that after authentication succeeds, the token is set with .
-
Token storage: As shown in the index.js file around line 445, Puter's client-side code stores the token in localStorage with the key 'puter.auth.token'. Your C# wrapper could do something similar - store the token after the first authentication and reuse it for subsequent sessions.
For your implementation:
- Have your C# wrapper show the authentication popup only once
- Store the received token securely in your application
- Reuse this token for subsequent API calls
- Provide a way for users to explicitly sign out if needed
This approach should eliminate the need for repeated authentication popups while still respecting the authentication flow.
Thank you.