A clean, Markdown-based publishing platform made for writers. Write together, and build a community. https://writefreely.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

29 lines
841 B

  1. /*
  2. * Copyright © 2018 A Bunch Tell LLC.
  3. *
  4. * This file is part of WriteFreely.
  5. *
  6. * WriteFreely is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License, included
  8. * in the LICENSE file in this source code package.
  9. */
  10. package writefreely
  11. // AuthenticateUser ensures a user with the given accessToken is valid. Call
  12. // it before any operations that require authentication or optionally associate
  13. // data with a user account.
  14. // Returns an error if the given accessToken is invalid. Otherwise the
  15. // associated user ID is returned.
  16. func AuthenticateUser(db writestore, accessToken string) (int64, error) {
  17. if accessToken == "" {
  18. return 0, ErrNoAccessToken
  19. }
  20. userID := db.GetUserID(accessToken)
  21. if userID == -1 {
  22. return 0, ErrBadAccessToken
  23. }
  24. return userID, nil
  25. }