2017-03-08 2 views
1

WSO2 IS에서 JWT 액세스 토큰을 얻으려고합니다. 나는 msf4j Oauth2 Security Sample에서 지시를 따르고, resource owner password 부여 유형으로 JWT 액세스 토큰을 얻을 수있었습니다. 하지만 외부에서 토큰을 인증하는 데 문제가 있습니다.WSO2IS JWT 액세스 토큰

토큰이 기본 "wso2carbon.jks"로 서명되지 않은 것으로 보입니다.

은 또한 "서비스 제공자"내 주장 구성은 JWT의 콘텐츠

그래서 내 질문에 반영되지 않은 : 어떻게 WSO2IS에서 JWT 서명 인증서를 config (설정)하는 방법?

도 : JWT에서 클레임을 조작하는 방법은 무엇입니까?

나는 성능 관심 밖으로 "성찰"엔드 포인트로 전환하지 않으려는, 나의 전략은

토큰 JWT의 진위의 확인 (로컬) 만 확인하려면 IS 신뢰하십시오이다 조언

감사

+0

... 나는 여전히 JWT 토큰의 주장을 조작하는 방법을 알아낼 필요가 말했다 : http://stackoverflow.com/questions/42626010/mandatory- 서비스 공급자 - 청구 - 항상 - 묻고 답하지 않는 openid-profil – Giovanni

답변

0

음, 내 자신의 잘못 인 것 같습니다.

나는 jose4j JWT 패키지를 사용하고 있었고 검증 실패 메시지가 계속 나타납니다.

msf4j 구현에 확인 후, 나는 nimbus-jose-jwt JWT 패키지로 전환하고, 아래

내 구현하고, 수행되었다.

저는 개인적으로 msf4j 친구들이보세요. 구현에 하나의 특정 별칭 (인증서)을 사용했기 때문에 (어떤 방법 으로든) 오는 토큰에 사용해야하는 인증서를 절대로 알 수 없습니다. 특히나는 당신이이 스레드에 모양을 제공 할 수 있다고 생각

import com.nimbusds.jose.JWSVerifier; 
import com.nimbusds.jose.crypto.RSASSAVerifier; 
import com.nimbusds.jwt.JWTClaimsSet; 
import com.nimbusds.jwt.SignedJWT; 
public class JwtParser { 

    private static final String KEYSTORE = System.getProperty("javax.net.ssl.trustStore"); 
    private static final String KEYSTORE_PASSWORD = System.getProperty("javax.net.ssl.trustStorePassword"); 

    private static Map<String, JWSVerifier> verifiers = getVerifiers(); 

    public static JWTClaimsSet verify(String jwt) throws Exception { 

       SignedJWT signedJWT = SignedJWT.parse(jwt); 
       if (!new Date().before(signedJWT.getJWTClaimsSet().getExpirationTime())) { 
        new Exception("token has expired"); 
       } 

       boolean notYet = true; 
       for(Iterator<JWSVerifier> it = verifiers.values().iterator(); notYet && it.hasNext();){ 
        JWSVerifier verifier = it.next(); 
        notYet = !signedJWT.verify(verifier); 
       } 

       if(notYet){ 
        throw new Exception("token verification failed"); 
       } 
       JWTClaimsSet claims = signedJWT.getJWTClaimsSet(); 
       if (claims == null) { 
        // Do something with claims 
        throw new Exception("non valid payload in token, failed"); 
       } 

       return claims; 
    } 

    private static Map<String, JWSVerifier> getVerifiers(){ 

     Map<String, JWSVerifier> verifiers = new HashMap<>(); 

     try (InputStream inputStream = new FileInputStream(KEYSTORE)) { 
      KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType()); 
      keystore.load(inputStream, KEYSTORE_PASSWORD.toCharArray()); 
      Enumeration<String> aliases = keystore.aliases(); 

      while(aliases.hasMoreElements()){ 
       String alias = aliases.nextElement(); 

       if(!keystore.isCertificateEntry(alias)){ 
        continue; 
       } 
       Certificate cert = keystore.getCertificate(alias); 
       if(cert == null){ 
        continue; 
       } 
       PublicKey key = cert.getPublicKey(); 
       verifiers.put(alias, new RSASSAVerifier((RSAPublicKey)key));   
      } 


     }catch(KeyStoreException | CertificateException | NoSuchAlgorithmException | IOException e){ 
      //TODO: report the exception 
     } 
     return verifiers; 
    } 

}