[GH-ISSUE #522] Web: User account & account sync #399

Closed
opened 2026-05-07 00:23:49 +02:00 by BreizhHardware · 5 comments

Originally created by @binwiederhier on GitHub (Nov 29, 2022).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/522

This ticket is meant to allow users to log in and sync account settings (as opposed to the current browser-store only feature).

Originally created by @binwiederhier on GitHub (Nov 29, 2022). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/522 This ticket is meant to allow users to log in and sync account settings (as opposed to the current browser-store only feature).
Author
Owner

@binwiederhier commented on GitHub (Dec 2, 2022):

I have been working on this. It's very very very rough. Code here: https://github.com/binwiederhier/ntfy/pull/526 -- It's like 20% done and very bad code.

Here are some raw notes.



ntfy data model
--

user
- user_id
- plan_id
- username
- password (hash)
- role (user, admin)

user_access
- user_id
- topic
- read
- write

user_subscription
- user_id
- base_url
- topic

user_setting

user_token
 - user_id
 - token
 - expires

plan
- plan_id
- name
- 

 

Flows:
- Login
  GET v1/user/token -> token
  Redirect
 

Endpoints:

GET v1/user/token
  {
    "token": "abcdef..."
  }

GET v1/user/account
  {
     "username": "phil",
     "role": "user",
     "plan": {
     	"id": 1,
     	"name": "ntfy Free"     	
     },
     "notification": {
       "sound": "ding",
       "min_priority": 1,
       "delete_after": 1234
     },
     "language": "de_DE",
     "users: [
       {
         "base_url": "https://ntfy.sh",
         "user": "phil",
         "pass": "*"
       }
     ],
     "subscriptions": [
      	{
      	  "base_url": "https://ntfy.sh",
      	  "topic": "mytopic"
      	}
     ],
     "access": [
        {
          "user": "phil",
          "topic": "mytopic",
          "read": true,
          "write": false
        }
     ],
     "limits": {
       "messages": 1000,
       "messages_available": 877,
       "emails": 16,
       "emails_available": 15,
       ...
     }     
  }
     

GET v1/user/account   // anonymous user
  {
     "username": "anonymous",
     "limits": {
       "messages": 1000,
       "messages_available": 877,
       "emails": 16,
       "emails_available": 15,
       ...
     }
  }
          
     
PUT v1/user/access
  {
    "user": "phil",
    "topic": "mytopic",
    "access": "private"
  }
<!-- gh-comment-id:1335820194 --> @binwiederhier commented on GitHub (Dec 2, 2022): I have been working on this. It's very very very rough. Code here: https://github.com/binwiederhier/ntfy/pull/526 -- It's like 20% done and very bad code. Here are some raw notes. ``` ntfy data model -- user - user_id - plan_id - username - password (hash) - role (user, admin) user_access - user_id - topic - read - write user_subscription - user_id - base_url - topic user_setting user_token - user_id - token - expires plan - plan_id - name - Flows: - Login GET v1/user/token -> token Redirect Endpoints: GET v1/user/token { "token": "abcdef..." } GET v1/user/account { "username": "phil", "role": "user", "plan": { "id": 1, "name": "ntfy Free" }, "notification": { "sound": "ding", "min_priority": 1, "delete_after": 1234 }, "language": "de_DE", "users: [ { "base_url": "https://ntfy.sh", "user": "phil", "pass": "*" } ], "subscriptions": [ { "base_url": "https://ntfy.sh", "topic": "mytopic" } ], "access": [ { "user": "phil", "topic": "mytopic", "read": true, "write": false } ], "limits": { "messages": 1000, "messages_available": 877, "emails": 16, "emails_available": 15, ... } } GET v1/user/account // anonymous user { "username": "anonymous", "limits": { "messages": 1000, "messages_available": 877, "emails": 16, "emails_available": 15, ... } } PUT v1/user/access { "user": "phil", "topic": "mytopic", "access": "private" } ```
Author
Owner

@binwiederhier commented on GitHub (Dec 3, 2022):

Implemented this:

curl -u ben:ben localhost:2586/user/auth
{"token":"1JntEz3EDrXYYj539wDiEgqRrukGQsVD"}

curl -H "Authorization: Bearer 1JntEz3EDrXYYj539wDiEgqRrukGQsVD" localhost:2586/user/account
{"username":"ben","role":"admin","language":"de-DE", "notification":{"sound":"dadum","min_priority":"","delete_after":0}}

This can now be used in the UI to log in and sync the config and subscriptions. I have it working to sync the language already. But it's really rough.

Server-side it's a few more tables, though I am contemplating collapsing all the tables into just one more column in the user table called settings and just storing a JSON blob in that.

<!-- gh-comment-id:1336251522 --> @binwiederhier commented on GitHub (Dec 3, 2022): Implemented this: ``` curl -u ben:ben localhost:2586/user/auth {"token":"1JntEz3EDrXYYj539wDiEgqRrukGQsVD"} curl -H "Authorization: Bearer 1JntEz3EDrXYYj539wDiEgqRrukGQsVD" localhost:2586/user/account {"username":"ben","role":"admin","language":"de-DE", "notification":{"sound":"dadum","min_priority":"","delete_after":0}} ``` This can now be used in the UI to log in and sync the config and subscriptions. I have it working to sync the language already. But it's really rough. Server-side it's a few more tables, though I am contemplating collapsing all the tables into just one more column in the user table called settings and just storing a JSON blob in that.
Author
Owner

@binwiederhier commented on GitHub (Dec 9, 2022):

Current progress:

https://user-images.githubusercontent.com/664597/206604453-ec679164-4fde-409c-bfa8-93a80459e039.mp4

Current ideas for API endpoints:


Login:
	GET /user/token
	{
	  "token": "abcdef..."
	}

Logout:
	DELETE /user/auth
	Authorization: Bearer abcdef...

Get user account (if not logged in):
	GET /user/account
	  {
	     "username": "anonymous",
	     "limits": {
	       "messages": 1000,
	       "messages_available": 877,
	       "emails": 16,
	       "emails_available": 15,
	       ...
	     }
	  }

Get account settings:
	GET /user/account
	Authorization: Bearer abcdef...	
	{
	     "username": "phil",
	     "role": "user",
	     "plan": {
	     	"id": 1,
	     	"name": "ntfy Free"     	
	     },
	     "notification": {
	       "sound": "ding",
	       "min_priority": 1,
	       "delete_after": 1234
	     },
	     "language": "de_DE",
	     "users: [
	       {
		 "id": "ewrwr-rwer-ewrwr-rwerwrwerwerrw",
		 "base_url": "https://ntfy.sh",
		 "user": "phil",
		 "pass": "*"
	       }
	     ],
	     "subscriptions": [
	      	{
	      	  "id": "adefsdf-dasd-dedsd-dasdasdadasd",
	      	  "base_url": "https://ntfy.sh",
	      	  "topic": "mytopic"
	      	}
	     ],
	     "access": [
		{
		  "user": "phil",
		  "topic": "mytopic",
		  "read": true,
		  "write": false
		}
	     ]
	     "limits": {
	       "messages": 1000,
	       "messages_available": 877,
	       "emails": 16,
	       "emails_available": 15,
	       ...
	     }     
	  }

Update simple settings:
	PUT /user/account
	Authorization: Bearer abcdef...
		
	{
	  "language": "de-DE",
	  "notification": {
	    "sound": "ding"
	  }
	}


Add subscription:
	PUT /user/subscription
	Authorization: Bearer abcdef...
		
	{
	  "base_url": "https://ntfy.sh",
	  "topic": "mytopic"
	}
	
	Response:
		{
		  "id": "adefsdf-dasd-dedsd-dasdasdadasd",
		  "base_url": "https://ntfy.sh",
		  "topic": "mytopic"
		}
	
	
Delete subscription:
	DELETE /user/subscription/adefsdf-dasd-dedsd-dasdasdadasd
	Authorization: Bearer abcdef...
<!-- gh-comment-id:1343728409 --> @binwiederhier commented on GitHub (Dec 9, 2022): Current progress: https://user-images.githubusercontent.com/664597/206604453-ec679164-4fde-409c-bfa8-93a80459e039.mp4 Current ideas for API endpoints: ``` Login: GET /user/token { "token": "abcdef..." } Logout: DELETE /user/auth Authorization: Bearer abcdef... Get user account (if not logged in): GET /user/account { "username": "anonymous", "limits": { "messages": 1000, "messages_available": 877, "emails": 16, "emails_available": 15, ... } } Get account settings: GET /user/account Authorization: Bearer abcdef... { "username": "phil", "role": "user", "plan": { "id": 1, "name": "ntfy Free" }, "notification": { "sound": "ding", "min_priority": 1, "delete_after": 1234 }, "language": "de_DE", "users: [ { "id": "ewrwr-rwer-ewrwr-rwerwrwerwerrw", "base_url": "https://ntfy.sh", "user": "phil", "pass": "*" } ], "subscriptions": [ { "id": "adefsdf-dasd-dedsd-dasdasdadasd", "base_url": "https://ntfy.sh", "topic": "mytopic" } ], "access": [ { "user": "phil", "topic": "mytopic", "read": true, "write": false } ] "limits": { "messages": 1000, "messages_available": 877, "emails": 16, "emails_available": 15, ... } } Update simple settings: PUT /user/account Authorization: Bearer abcdef... { "language": "de-DE", "notification": { "sound": "ding" } } Add subscription: PUT /user/subscription Authorization: Bearer abcdef... { "base_url": "https://ntfy.sh", "topic": "mytopic" } Response: { "id": "adefsdf-dasd-dedsd-dasdasdadasd", "base_url": "https://ntfy.sh", "topic": "mytopic" } Delete subscription: DELETE /user/subscription/adefsdf-dasd-dedsd-dasdasdadasd Authorization: Bearer abcdef... ```
Author
Owner

@ngerstle commented on GitHub (Feb 5, 2023):

I'm curious- does this imply that a single user has the same subscriptions on all clients they log in with?
(Personally, I would prefer not to sync in all cases- I can see having subscriptions to different topics on different devices- this could be handled by using different accounts for different devices, but I'm not sure that's sustainable?)

<!-- gh-comment-id:1416898475 --> @ngerstle commented on GitHub (Feb 5, 2023): I'm curious- does this imply that a single user has the same subscriptions on all clients they log in with? (Personally, I would prefer not to sync in all cases- I can see having subscriptions to different topics on different devices- this could be handled by using different accounts for different devices, but I'm not sure that's sustainable?)
Author
Owner

@RokeJulianLockhart commented on GitHub (Feb 6, 2023):

@ngerstle, all that would be necessary would be different device profiles per account.

<!-- gh-comment-id:1419876542 --> @RokeJulianLockhart commented on GitHub (Feb 6, 2023): @ngerstle, all that would be necessary would be different device profiles per account.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#399
No description provided.