Class SpotifyLoginService

java.lang.Object
org.localify.auth.login.SpotifyLoginService

@Service public class SpotifyLoginService extends Object
Service for handling Spotify login.
  • Constructor Details

    • SpotifyLoginService

      public SpotifyLoginService(UserSeedRepository userSeedRepository, UserCityRepository userCityRepository, SpotifyService spotifyService, AccountLinkTokenRepository accountLinkTokenRepository, UserRepository userRepository, ServletUtils servletUtils, se.michaelthelin.spotify.SpotifyApi spotifyApi, UserService userService, jakarta.persistence.EntityManager entityManager, AccountMergingService accountMergingService)
      Constructs a new SpotifyLoginService.
      Parameters:
      userSeedRepository - The user seed repository.
      userCityRepository - The user city repository.
      spotifyService - The Spotify service.
      accountLinkTokenRepository - The account link token repository.
      userRepository - The user repository.
      servletUtils - The servlet utilities.
      spotifyApi - The Spotify API client.
      userService - The user service.
      entityManager - The entity manager.
      accountMergingService - The account merging service.
  • Method Details

    • getRedirectUri

      public URI getRedirectUri(String generatedState)
      Gets the Spotify redirect URI for the authorization code flow.
      Parameters:
      generatedState - The state parameter to use.
      Returns:
      The redirect URI.
    • findOrCreate

      public User findOrCreate(SpotifyUserDetails details)
      Finds or creates a user based on Spotify user details.
      Parameters:
      details - The Spotify user details.
      Returns:
      The found or created user.
    • login

      @Transactional public User login(String code)
      Logs in a user with a Spotify authorization code.
      Parameters:
      code - The authorization code.
      Returns:
      The logged-in or created user.
    • dispatchSpotifyUserInfo

      @Transactional(propagation=REQUIRES_NEW) public void dispatchSpotifyUserInfo(User user)
      Dispatches a task to update the user's Spotify information.
      Parameters:
      user - The user to update.
    • link

      @Transactional public String link(String code, UUID linkToken)
      Links a Spotify account to an existing user account.
      Parameters:
      code - The Spotify authorization code.
      linkToken - The account link token.
      Returns:
      A query string to be appended to the redirect URI, or an empty string if no merge is required.