All Downloads are FREE. Search and download functionalities are using the official Maven repository.

xyz.gianlu.librespot.api.handlers.TokensHandler Maven / Gradle / Ivy

There is a newer version: 1.6.4
Show newest version
package xyz.gianlu.librespot.api.handlers;

import com.google.gson.JsonObject;
import io.undertow.server.HttpServerExchange;
import org.jetbrains.annotations.NotNull;
import xyz.gianlu.librespot.api.SessionWrapper;
import xyz.gianlu.librespot.api.Utils;
import xyz.gianlu.librespot.core.Session;
import xyz.gianlu.librespot.core.TokenProvider;

import java.util.Deque;
import java.util.Map;

public final class TokensHandler extends AbsSessionHandler {

    public TokensHandler(@NotNull SessionWrapper wrapper) {
        super(wrapper);
    }

    @Override
    protected void handleRequest(@NotNull HttpServerExchange exchange, @NotNull Session session) throws Exception {
        exchange.startBlocking();
        if (exchange.isInIoThread()) {
            exchange.dispatch(this);
            return;
        }

        Map> params = Utils.readParameters(exchange);
        String scope = Utils.getFirstString(params, "scope");
        if (scope == null) {
            Utils.invalidParameter(exchange, "scope");
            return;
        }

        TokenProvider.StoredToken token = session.tokens().getToken(scope);
        JsonObject obj = new JsonObject();
        obj.addProperty("token", token.accessToken);
        obj.addProperty("timestamp", token.timestamp);
        obj.addProperty("expiresIn", token.expiresIn);
        exchange.getResponseSender().send(obj.toString());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy