@@ -149,6 +149,7 @@ func GetAuthFromReq(c *fiber.Ctx) (*string, *string, *string, *string, error) {
149149
150150 isBasic := false
151151 nodid := ""
152+ notoken := ""
152153 var username string
153154
154155 // Define a regular expression to match the oauth_token
@@ -161,7 +162,7 @@ func GetAuthFromReq(c *fiber.Ctx) (*string, *string, *string, *string, error) {
161162 var did * string
162163 basicAuthUsernamePassword , err = cryption .Base64URLDecode (base64pass )
163164 if err != nil {
164- return & nodid , & fallbackRoute , nil , nil , err
165+ return & nodid , & fallbackRoute , nil , & notoken , err
165166 }
166167
167168 // separate the username and password
@@ -175,32 +176,32 @@ func GetAuthFromReq(c *fiber.Ctx) (*string, *string, *string, *string, error) {
175176 if err .Error () == "invalid credentials" {
176177 // test if password is an app password thru regex
177178 if ! regexp .MustCompile (`^[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}$` ).MatchString (authPassword ) {
178- return & nodid , & fallbackRoute , nil , nil , errors .New ("invalid app password" )
179+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("invalid app password" )
179180 }
180181
181182 res , pds , err := blueskyapi .Authenticate (username , authPassword )
182183 if err != nil {
183- return & nodid , & fallbackRoute , nil , nil , err
184+ return & nodid , & fallbackRoute , nil , & notoken , err
184185 }
185186
186187 access_token_expiry , err := cryption .GetJWTTokenExpirationUnix (res .AccessJwt )
187188 if err != nil {
188- return & nodid , & fallbackRoute , nil , nil , errors .New ("failed to get access token expiry" )
189+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("failed to get access token expiry" )
189190 }
190191 refresh_token_expiry , err := cryption .GetJWTTokenExpirationUnix (res .RefreshJwt )
191192 if err != nil {
192- return & nodid , & fallbackRoute , nil , nil , errors .New ("failed to get refresh token expiry" )
193+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("failed to get refresh token expiry" )
193194 }
194195
195196 _ , err = db_controller .StoreTokenBasic (res .DID , * pds , res .AccessJwt , res .RefreshJwt , username , authPassword , * access_token_expiry , * refresh_token_expiry )
196197
197198 if err != nil {
198- return & nodid , & fallbackRoute , nil , nil , err
199+ return & nodid , & fallbackRoute , nil , & notoken , err
199200 }
200201
201202 return & res .DID , pds , nil , & res .AccessJwt , nil // TODO: Maybe change the uuid to something for here?
202203 } else {
203- return & nodid , & fallbackRoute , nil , nil , err
204+ return & nodid , & fallbackRoute , nil , & notoken , err
204205 }
205206 }
206207
@@ -209,7 +210,7 @@ func GetAuthFromReq(c *fiber.Ctx) (*string, *string, *string, *string, error) {
209210 re := regexp .MustCompile (`oauth_token="([^"]+)"` )
210211 matches := re .FindStringSubmatch (authHeader )
211212 if len (matches ) < 2 {
212- return & nodid , & fallbackRoute , nil , nil , errors .New ("oauth token not found" )
213+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("oauth token not found" )
213214 }
214215
215216 oauthToken := matches [1 ]
@@ -221,7 +222,7 @@ func GetAuthFromReq(c *fiber.Ctx) (*string, *string, *string, *string, error) {
221222 tokenData , err = ConvertV1TokenToV2 (oauthToken )
222223
223224 if err != nil {
224- return & nodid , & fallbackRoute , nil , nil , err
225+ return & nodid , & fallbackRoute , nil , & notoken , err
225226 }
226227
227228 } else {
@@ -230,18 +231,18 @@ func GetAuthFromReq(c *fiber.Ctx) (*string, *string, *string, *string, error) {
230231 })
231232
232233 if err != nil {
233- return & nodid , & fallbackRoute , nil , nil , errors .New ("invalid token" )
234+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("invalid token" )
234235 }
235236
236237 if ! token .Valid {
237238 if tokenData .ServerIdentifier == "" {
238- return & nodid , & fallbackRoute , nil , nil , errors .New ("invalid token" )
239+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("invalid token" )
239240 } else if tokenData .ServerIdentifier != configData .ServerIdentifier {
240- return & nodid , & fallbackRoute , nil , nil , errors .New ("incorrect server" )
241+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("incorrect server" )
241242
242243 }
243244
244- return & nodid , & fallbackRoute , nil , nil , errors .New ("invalid token" )
245+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("invalid token" )
245246 }
246247 }
247248
@@ -258,7 +259,7 @@ func GetAuthFromReq(c *fiber.Ctx) (*string, *string, *string, *string, error) {
258259 accessJwt , refreshJwt , access_expiry , refresh_expiry , userPDS , err = db_controller .GetToken (string (userDID ), string (tokenUUID ), encryptionKey , tokenType ) // Use token version 2 for OAuth
259260
260261 if err != nil {
261- return & nodid , & fallbackRoute , nil , nil , err
262+ return & nodid , & fallbackRoute , nil , & notoken , err
262263 }
263264 }
264265
@@ -294,25 +295,25 @@ func GetAuthFromReq(c *fiber.Ctx) (*string, *string, *string, *string, error) {
294295 } else {
295296 db_controller .DeleteToken (string (userDID ), string (tokenUUID ))
296297 }
297- return & nodid , & fallbackRoute , nil , nil , errors .New ("refresh token has expired" )
298+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("refresh token has expired" )
298299 }
299300
300301 // Our refresh token is still valid. Lets refresh our access token.
301302 new_auth , err := blueskyapi .RefreshToken (* userPDS , * refreshJwt )
302303
303304 if err != nil {
304- return & nodid , & fallbackRoute , nil , nil , err
305+ return & nodid , & fallbackRoute , nil , & notoken , err
305306 }
306307
307308 accessJwt = & new_auth .AccessJwt
308309
309310 access_token_expiry , err := cryption .GetJWTTokenExpirationUnix (new_auth .AccessJwt )
310311 if err != nil {
311- return & nodid , & fallbackRoute , nil , nil , errors .New ("failed to get access token expiry" )
312+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("failed to get access token expiry" )
312313 }
313314 refresh_token_expiry , err := cryption .GetJWTTokenExpirationUnix (new_auth .RefreshJwt )
314315 if err != nil {
315- return & nodid , & fallbackRoute , nil , nil , errors .New ("failed to get refresh token expiry" )
316+ return & nodid , & fallbackRoute , nil , & notoken , errors .New ("failed to get refresh token expiry" )
316317 }
317318
318319 // TODO: Recheck if the user id is still bound to that PDS
0 commit comments