yourkarma / JWT

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

Question; How to use JWTBuilder's encode in Swift #130

Open SpacyRicochet opened 7 years ago

SpacyRicochet commented 7 years ago

I am having trouble understanding the syntax of JWTBuilder's method chaining in Swift.

What would be the equivalent in Swift 3.0 of this line in Objective-C?

[JWTBuilder encodePayload:payload].secret(secret).algorithm(algorithm).encode;

Using the deprecated old method works fine, but I was wondering how to do this properly.

lolgear commented 7 years ago

@SpacyRicochet Hi!

What are you looking for? Yes, deprecated method is fine now. In future it will be back. ( awesome phrase )

        let payload: [AnyHashable:Any] = [:]
        let secret = ""
        let algorithm: JWTAlgorithm = JWTAlgorithmHSBase()
        let value = JWTBuilder.encodePayload(payload).secret(secret)?.algorithm(algorithm)?.encode
SpacyRicochet commented 7 years ago

Huh, weird. Somehow that failed to work for me spectacularly. But I might be doing something wrong or relying too much on code completion. Will get back to you on that ;)

lolgear commented 7 years ago

@SpacyRicochet you could look at JWTDesktopSwift for JWT usage in Swift