mirror of
https://github.com/wahyd4/libr-ios.git
synced 2026-08-09 05:06:46 +10:00
use JWT decode token with secret(email)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user