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

io.castled.utils.OAuthStateStore Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package io.castled.utils;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import lombok.extern.slf4j.Slf4j;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.UUID;

@Slf4j
@Singleton
public class OAuthStateStore {

    private static final String OAUTH_NS = "oauth:";

    private final GenericKeyValueStore kvStore;

    @Inject
    public OAuthStateStore(GenericKeyValueStore kvStore) {
        this.kvStore = kvStore;
    }

    public String persistOAuthState(String state) {
        String uuid = UUID.randomUUID().toString();
        kvStore.putKey(OAUTH_NS, uuid, (int) TimeUtils.minutesToMillis(30), state);
        return uuid;
    }

    public String getOAuthState(String stateId) {
        return kvStore.getKey(OAUTH_NS, stateId);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy