use JWT decode token with secret(email)

This commit is contained in:
yunlzheng
2015-08-31 01:44:44 +08:00
parent ad21ffb380
commit 27ac8c6c20
3 changed files with 23 additions and 5 deletions
+2
View File
@@ -6,6 +6,8 @@ target 'librx' do
pod 'Alamofire', '~> 1.3'
pod 'SwiftyJSON', '~> 2.2.1'
pod 'Spring', '~> 1.0.3'
pod 'JSONWebToken'
pod "JWTDecode", '~> 0.3'
end
target 'librxTests' do
+9
View File
@@ -1,15 +1,24 @@
PODS:
- Alamofire (1.3.1)
- CryptoSwift (0.0.10)
- JSONWebToken (1.3.0):
- CryptoSwift (= 0.0.10)
- JWTDecode (0.3.2)
- Spring (1.0.3)
- SwiftyJSON (2.2.1)
DEPENDENCIES:
- Alamofire (~> 1.3)
- JSONWebToken
- JWTDecode (~> 0.3)
- Spring (~> 1.0.3)
- SwiftyJSON (~> 2.2.1)
SPEC CHECKSUMS:
Alamofire: e4ab637e3195b645c814b87a652373439e59f2a4
CryptoSwift: 3b886d001f50deb65623a8967d68f6b8bf8d9ba1
JSONWebToken: 14e526aba3efc39c9c23be51eab8caf65e7ee933
JWTDecode: 1052abb787255297071b91e1e8337f828dbb01c3
Spring: 3f02b5dc3308572ef177b3cad0fa7bbc4b0706f7
SwiftyJSON: ae2d0a3d68025d136602a33c4ee215091ced3e33
+12 -5
View File
@@ -10,6 +10,8 @@ import Foundation
import Alamofire
import SwiftyJSON
import JWTDecode
import JWT
struct LibrxService {
@@ -121,13 +123,18 @@ struct LibrxService {
Alamofire.request(.POST, urlString, parameters: parameters)
.response{(_,_, json, _) in
let data = JSON(data: json! as! NSData)
let data = JSON(data: json!)
let jwt = data["user"]["token"].stringValue
// let payload = JWTDecoder.payloadWithError(jwt,error:&error)
//let payload = A0JWTDecoder.payloadOfJWT(jwt, error: &error) as Dictionary
response(token: jwt)
let result: DecodeResult = JWT.decode(jwt,.HS256(email))
switch result {
case .Success(let payload):
print("payload:\(payload)")
response(token: jwt)
case .Failure(let invalidToken):
print("invalidate token")
// TODO: Failure handler
}
}