Package com.livefyre.jwt

Source Code of com.livefyre.jwt.JWTAuthToken

package com.livefyre.jwt;

import java.security.InvalidKeyException;
import java.security.SignatureException;

import com.google.gson.JsonObject;

import net.oauth.jsontoken.JsonToken;
import net.oauth.jsontoken.crypto.HmacSHA256Signer;

public class JWTAuthToken {
    private JsonToken mToken;

    public JWTAuthToken(String networkName, String networkSecret,
            String userId, String displayName, double expires)
            throws InvalidKeyException {
        HmacSHA256Signer signer = new HmacSHA256Signer(null, null,
                networkSecret.getBytes());
        mToken = new JsonToken(signer);
        JsonObject tokenJSON = mToken.getPayloadAsJsonObject();
        tokenJSON.addProperty("domain", networkName);
        tokenJSON.addProperty("user_id", userId);
        tokenJSON.addProperty("display_name", displayName);
        tokenJSON.addProperty("expires", expires);
    }

    public String toString() {
        try {
            return mToken.serializeAndSign();
        } catch (SignatureException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return "error";
        }
    }
}
TOP

Related Classes of com.livefyre.jwt.JWTAuthToken

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.