forked from tangled.org/core
this repo has no description
at master 3.5 kB view raw
1package db 2 3type OAuthRequest struct { 4 ID uint 5 AuthserverIss string 6 Handle string 7 State string 8 Did string 9 PdsUrl string 10 PkceVerifier string 11 DpopAuthserverNonce string 12 DpopPrivateJwk string 13} 14 15func SaveOAuthRequest(e Execer, oauthRequest OAuthRequest) error { 16 _, err := e.Exec(` 17 insert into oauth_requests ( 18 auth_server_iss, 19 state, 20 handle, 21 did, 22 pds_url, 23 pkce_verifier, 24 dpop_auth_server_nonce, 25 dpop_private_jwk 26 ) values (?, ?, ?, ?, ?, ?, ?, ?)`, 27 oauthRequest.AuthserverIss, 28 oauthRequest.State, 29 oauthRequest.Handle, 30 oauthRequest.Did, 31 oauthRequest.PdsUrl, 32 oauthRequest.PkceVerifier, 33 oauthRequest.DpopAuthserverNonce, 34 oauthRequest.DpopPrivateJwk, 35 ) 36 return err 37} 38 39func GetOAuthRequestByState(e Execer, state string) (OAuthRequest, error) { 40 var req OAuthRequest 41 err := e.QueryRow(` 42 select 43 id, 44 auth_server_iss, 45 handle, 46 state, 47 did, 48 pds_url, 49 pkce_verifier, 50 dpop_auth_server_nonce, 51 dpop_private_jwk 52 from oauth_requests 53 where state = ?`, state).Scan( 54 &req.ID, 55 &req.AuthserverIss, 56 &req.Handle, 57 &req.State, 58 &req.Did, 59 &req.PdsUrl, 60 &req.PkceVerifier, 61 &req.DpopAuthserverNonce, 62 &req.DpopPrivateJwk, 63 ) 64 return req, err 65} 66 67func DeleteOAuthRequestByState(e Execer, state string) error { 68 _, err := e.Exec(` 69 delete from oauth_requests 70 where state = ?`, state) 71 return err 72} 73 74type OAuthSession struct { 75 ID uint 76 Handle string 77 Did string 78 PdsUrl string 79 AccessJwt string 80 RefreshJwt string 81 AuthServerIss string 82 DpopPdsNonce string 83 DpopAuthserverNonce string 84 DpopPrivateJwk string 85 Expiry string 86} 87 88func SaveOAuthSession(e Execer, session OAuthSession) error { 89 _, err := e.Exec(` 90 insert into oauth_sessions ( 91 did, 92 handle, 93 pds_url, 94 access_jwt, 95 refresh_jwt, 96 auth_server_iss, 97 dpop_auth_server_nonce, 98 dpop_private_jwk, 99 expiry 100 ) values (?, ?, ?, ?, ?, ?, ?, ?, ?)`, 101 session.Did, 102 session.Handle, 103 session.PdsUrl, 104 session.AccessJwt, 105 session.RefreshJwt, 106 session.AuthServerIss, 107 session.DpopAuthserverNonce, 108 session.DpopPrivateJwk, 109 session.Expiry, 110 ) 111 return err 112} 113 114func RefreshOAuthSession(e Execer, did string, accessJwt, refreshJwt, expiry string) error { 115 _, err := e.Exec(` 116 update oauth_sessions 117 set access_jwt = ?, refresh_jwt = ?, expiry = ? 118 where did = ?`, 119 accessJwt, 120 refreshJwt, 121 expiry, 122 did, 123 ) 124 return err 125} 126 127func GetOAuthSessionByDid(e Execer, did string) (*OAuthSession, error) { 128 var session OAuthSession 129 err := e.QueryRow(` 130 select 131 id, 132 did, 133 handle, 134 pds_url, 135 access_jwt, 136 refresh_jwt, 137 auth_server_iss, 138 dpop_auth_server_nonce, 139 dpop_private_jwk, 140 expiry 141 from oauth_sessions 142 where did = ?`, did).Scan( 143 &session.ID, 144 &session.Did, 145 &session.Handle, 146 &session.PdsUrl, 147 &session.AccessJwt, 148 &session.RefreshJwt, 149 &session.AuthServerIss, 150 &session.DpopAuthserverNonce, 151 &session.DpopPrivateJwk, 152 &session.Expiry, 153 ) 154 return &session, err 155} 156 157func DeleteOAuthSessionByDid(e Execer, did string) error { 158 _, err := e.Exec(` 159 delete from oauth_sessions 160 where did = ?`, did) 161 return err 162} 163 164func UpdateDpopPdsNonce(e Execer, did string, dpopPdsNonce string) error { 165 _, err := e.Exec(` 166 update oauth_sessions 167 set dpop_pds_nonce = ? 168 where did = ?`, 169 dpopPdsNonce, 170 did, 171 ) 172 return err 173}