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

com.microsoft.azure.eventhubs.JsonSecurityToken Maven / Gradle / Ivy

Go to download

Please note, a newer package azure-messaging-eventhubs for Azure Event Hubs is available at https://search.maven.org/artifact/com.azure/azure-messaging-eventhubs as of February 2020. While this package will continue to receive critical bug fixes, we strongly encourage you to upgrade. Read the migration guide at https://aka.ms/azsdk/java/migrate/eh for more details.

There is a newer version: 3.3.0
Show newest version
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.azure.eventhubs;

import java.text.ParseException;
import java.util.Date;

import com.microsoft.azure.eventhubs.impl.ClientConstants;
import com.nimbusds.jwt.JWT;
import com.nimbusds.jwt.JWTClaimsSet;
import com.nimbusds.jwt.JWTParser;

/**
 * Extend SecurityToken with some specifics for a JSon Web Token  
 *
 */
public class JsonSecurityToken extends SecurityToken {
    /**
     * Construct from a raw JWT.
     * @param rawToken   the JWT token data
     * @param audience   audience of the token
     * @throws ParseException if the token cannot be parsed
     */
    public JsonSecurityToken(final String rawToken, final String audience) throws ParseException {
        super(rawToken, getExpirationDateTimeUtcFromToken(rawToken), audience, ClientConstants.JWT_TOKEN_TYPE);
    }
    
    static Date getExpirationDateTimeUtcFromToken(final String token) throws ParseException {
        JWT jwt = JWTParser.parse(token);
        JWTClaimsSet claims = jwt.getJWTClaimsSet();
        return claims.getExpirationTime();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy