use of se.michaelthelin.spotify.model_objects.credentials.AuthorizationCodeCredentials in project spotifybot by NotEchoDE.
the class CallbackController method spotifyCallback.
@SneakyThrows
@GetMapping("/spotify/callback")
public String spotifyCallback(@RequestParam(name = "code", defaultValue = "null") String code, @CookieValue(name = "session", defaultValue = "null") String session, Model model) {
if (code.equals("null"))
return "redirect:/erorr?code=503";
if (sessionManagementService.getUser(session) == null)
return "redirect:/erorr?code=503";
BotUser user = sessionManagementService.getUser(session);
AuthorizationCodeCredentials codeCredentials = spotifyApi.authorizationCode(code).build().execute();
if (user.spotifyTokens() != null) {
user.spotifyTokens().setAccessToken(codeCredentials.getAccessToken());
user.spotifyTokens().setRefreshToken(codeCredentials.getRefreshToken());
} else
user.addTokenPair(new TokenPair(0L, codeCredentials.getAccessToken(), codeCredentials.getRefreshToken(), TokenType.SPOTIFY));
repository.saveAndFlush(user);
botInstanceManagementService.startInstance(user);
return "redirect:/dashboard";
}
use of se.michaelthelin.spotify.model_objects.credentials.AuthorizationCodeCredentials in project spotify-web-api-java by spotify-web-api-java.
the class AuthorizationCodeExample method authorizationCode_Async.
public static void authorizationCode_Async() {
try {
final CompletableFuture<AuthorizationCodeCredentials> authorizationCodeCredentialsFuture = authorizationCodeRequest.executeAsync();
// Thread free to do other tasks...
// Example Only. Never block in production code.
final AuthorizationCodeCredentials authorizationCodeCredentials = authorizationCodeCredentialsFuture.join();
// Set access and refresh token for further "spotifyApi" object usage
spotifyApi.setAccessToken(authorizationCodeCredentials.getAccessToken());
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());
System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
} catch (CompletionException e) {
System.out.println("Error: " + e.getCause().getMessage());
} catch (CancellationException e) {
System.out.println("Async operation cancelled.");
}
}
use of se.michaelthelin.spotify.model_objects.credentials.AuthorizationCodeCredentials in project spotify-web-api-java by spotify-web-api-java.
the class AuthorizationCodeRefreshExample method authorizationCodeRefresh_Async.
public static void authorizationCodeRefresh_Async() {
try {
final CompletableFuture<AuthorizationCodeCredentials> authorizationCodeCredentialsFuture = authorizationCodeRefreshRequest.executeAsync();
// Thread free to do other tasks...
// Example Only. Never block in production code.
final AuthorizationCodeCredentials authorizationCodeCredentials = authorizationCodeCredentialsFuture.join();
// Set access token for further "spotifyApi" object usage
spotifyApi.setAccessToken(authorizationCodeCredentials.getAccessToken());
System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
} catch (CompletionException e) {
System.out.println("Error: " + e.getCause().getMessage());
} catch (CancellationException e) {
System.out.println("Async operation cancelled.");
}
}
use of se.michaelthelin.spotify.model_objects.credentials.AuthorizationCodeCredentials in project spotify-web-api-java by spotify-web-api-java.
the class AuthorizationCodeRefreshExample method authorizationCodeRefresh_Sync.
public static void authorizationCodeRefresh_Sync() {
try {
final AuthorizationCodeCredentials authorizationCodeCredentials = authorizationCodeRefreshRequest.execute();
// Set access and refresh token for further "spotifyApi" object usage
spotifyApi.setAccessToken(authorizationCodeCredentials.getAccessToken());
System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
} catch (IOException | SpotifyWebApiException | ParseException e) {
System.out.println("Error: " + e.getMessage());
}
}
use of se.michaelthelin.spotify.model_objects.credentials.AuthorizationCodeCredentials in project spotify-web-api-java by spotify-web-api-java.
the class AuthorizationCodePKCEExample method authorizationCode_Async.
public static void authorizationCode_Async() {
try {
final CompletableFuture<AuthorizationCodeCredentials> authorizationCodeCredentialsFuture = authorizationCodePKCERequest.executeAsync();
// Thread free to do other tasks...
// Example Only. Never block in production code.
final AuthorizationCodeCredentials authorizationCodeCredentials = authorizationCodeCredentialsFuture.join();
// Set access and refresh token for further "spotifyApi" object usage
spotifyApi.setAccessToken(authorizationCodeCredentials.getAccessToken());
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());
System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
} catch (CompletionException e) {
System.out.println("Error: " + e.getCause().getMessage());
} catch (CancellationException e) {
System.out.println("Async operation cancelled.");
}
}
Aggregations