objective categorical abstract machine language personal data server
65
fork

Configure Feed

Select the types of activity you want to include in your feed.

Track session IP and user agent

futurGH 3ef2ebd0 2a699dd1

+17 -7
+3
migrations/002_track_oauth_sessions.sql
··· 1 1 ALTER TABLE oauth_tokens ADD COLUMN created_at INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP; 2 2 ALTER TABLE oauth_tokens ADD COLUMN last_refreshed_at INTEGER NOT NULL DEFAULT CURRENT_TIMESTAMP; 3 3 4 + ALTER TABLE oauth_tokens ADD COLUMN last_ip TEXT NOT NULL DEFAULT ''; 5 + ALTER TABLE oauth_tokens ADD COLUMN last_user_agent TEXT; 6 + 4 7 CREATE INDEX IF NOT EXISTS oauth_tokens_did_idx ON oauth_tokens(did);
+5 -1
pegasus/lib/api/oauth_/token.ml
··· 6 6 Xrpc.handler ~auth:DPoP (fun ctx -> 7 7 let%lwt req = Xrpc.parse_body ctx.req Types.token_request_of_yojson in 8 8 let proof = Auth.get_dpop_proof_exn ctx.auth in 9 + let ip = Dream.client ctx.req in 10 + let user_agent = Dream.header ctx.req "User-Agent" in 9 11 match req.grant_type with 10 12 | "authorization_code" -> ( 11 13 match req.code with ··· 104 106 ; scope= orig_req.scope 105 107 ; created_at= now_ms 106 108 ; last_refreshed_at= now_ms 107 - ; expires_at } 109 + ; expires_at 110 + ; last_ip= ip 111 + ; last_user_agent= user_agent } 108 112 in 109 113 let nonce = Dpop.next_nonce () in 110 114 Dream.json
-1
pegasus/lib/data_store.ml
··· 1 1 open Util.Rapper 2 - open Util.Syntax 3 2 4 3 module Types = struct 5 4 type actor =
+6 -4
pegasus/lib/oauth/queries.ml
··· 83 83 @@ [%rapper 84 84 execute 85 85 {sql| 86 - INSERT INTO oauth_tokens (refresh_token, client_id, did, dpop_jkt, scope, created_at, expires_at, last_refreshed_at) 87 - VALUES (%string{refresh_token}, %string{client_id}, %string{did}, %string{dpop_jkt}, %string{scope}, %int{created_at}, %int{expires_at}, %int{last_refreshed_at}) 86 + INSERT INTO oauth_tokens (refresh_token, client_id, did, dpop_jkt, scope, created_at, expires_at, last_refreshed_at, last_ip, last_user_agent) 87 + VALUES (%string{refresh_token}, %string{client_id}, %string{did}, %string{dpop_jkt}, %string{scope}, %int{created_at}, %int{expires_at}, %int{last_refreshed_at}, %string{last_ip}, %string?{last_user_agent}) 88 88 |sql} 89 89 record_in] 90 90 token ··· 95 95 get_opt 96 96 {sql| 97 97 SELECT @string{refresh_token}, @string{client_id}, @string{did}, 98 - @string{dpop_jkt}, @string{scope}, @int{created_at}, @int{expires_at}, @int{last_refreshed_at} 98 + @string{dpop_jkt}, @string{scope}, @int{created_at}, @int{expires_at}, 99 + @int{last_refreshed_at}, @string{last_ip}, @string?{last_user_agent} 99 100 FROM oauth_tokens 100 101 WHERE refresh_token = %string{refresh_token} 101 102 |sql} ··· 129 130 get_many 130 131 {sql| 131 132 SELECT @string{refresh_token}, @string{client_id}, @string{did}, 132 - @string{dpop_jkt}, @string{scope}, @int{created_at}, @int{expires_at}, @int{last_refreshed_at} 133 + @string{dpop_jkt}, @string{scope}, @int{created_at}, @int{expires_at}, 134 + @int{last_refreshed_at}, @string{last_ip}, @string?{last_user_agent} 133 135 FROM oauth_tokens 134 136 WHERE did = %string{did} 135 137 ORDER BY expires_at ASC
+3 -1
pegasus/lib/oauth/types.ml
··· 69 69 ; scope: string 70 70 ; created_at: int 71 71 ; last_refreshed_at: int 72 - ; expires_at: int } 72 + ; expires_at: int 73 + ; last_ip: string 74 + ; last_user_agent: string option [@default None] } 73 75 [@@deriving yojson {strict= false}]