yourkarma / JWT

A JSON Web Token implementation in Objective-C.
MIT License
351 stars 107 forks source link

claimSet empty #158

Closed icedice closed 6 years ago

icedice commented 6 years ago

New Issue Checklist

Issue Description and Steps

I'm missing something. When i decode a jwt the claimSet in result!.successResult.claimsSet always end up as nil, this happens even though i pass a claimSet to my JTWDecoindBuilder and it validates perfectly against the JWT. What am I missing here I just need to access the subject and thought I would be able to do it like so: result!.successResult.claimsSet.subject I guess I could dig it out of the headerAndPayloadDictionary, but surely thats not the right way to do it.

lolgear commented 6 years ago

@icedice Hi! Nice to hear, I have not found any appropriate invocation of SuccessResult with claimsSet. It seems a bug.

Could you describe an expected behavior more precisely? Should claims be mixed with headers and payload?

icedice commented 6 years ago

I would simply expect that when I decode a JWT with the JWTDecodingBuilder, and the decoding is a success, then I should be able to access standard claims in the ClaimSet in successResult.claimsSet like the issuer and the subject, but the claimSet seems to be nil always which is what is puzzling me...

Here is my code:

   var crypto: JWTCryptoKeyProtocol? = nil
            do {
                crypto = try JWTCryptoKeyPublic(pemEncoded: publickey, parameters: nil)
            }
            catch let error {
                NSLog("error: \(error)")
            }

            guard let theCrypto = crypto else {
                return
            }

            let algorithm = JWTAlgorithmNameRS256
            guard let holder = JWTAlgorithmRSFamilyDataHolder().signKey(theCrypto)?.verifyKey(theCrypto)?.secretData(publickey.data(using: .utf8)!)?.algorithmName(algorithm) else {
                return
            }

            let claimsSet = JWTClaimsSet()
           claimsSet.issuer = "MY ISSUER GOES HERE";
           claimsSet.audience = "AUD GOES HERE";

            guard let decoding = JWTDecodingBuilder.decodeMessage(token).claimsSet(claimsSet)?.addHolder(holder) as? JWTDecodingBuilder else{
                return
            }

            let result = decoding.decode

            let claims = result!.successResult!.claimsSet // nil
lolgear commented 6 years ago

@icedice try latest master

lolgear commented 6 years ago

@icedice could be closed?

icedice commented 6 years ago

Yes. sorry. The issue is resolved and can be closed.