Get user ID from JWT (JSON web token)Returning JSON from a PHP ScriptHow do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How do I get ASP.NET Web API to return JSON instead of XML using Chrome?Is there any JSON Web Token (JWT) example in C#?Google oAuth 2.0 (JWT token request) for Service ApplicationPython: Encode/Decode dictionary contains list to/from jsonInvalidating JSON Web TokensValidate Live.com (Microsoft account) JWT tokenRetrieving JWT from Google+ will not validateJWT (JSON Web Token) automatic prolongation of expiration
Is there some sort of French saying for "a person's signature move"?
What's this constructed number's starter?
"syntax error near unexpected token" after editing .bashrc
How to calculate the power level of a Commander deck?
Did the Byzantines ever attempt to move their capital to Rome?
Why does the UK Prime Minister need the permission of Parliament to call a general election?
Types of tablet... a tablet secretion
Can taking my 1-week-old on a 6-7 hours journey in the car lead to medical complications?
Dirac large numbers hypothesis
How to create large inductors (1H) for audio use?
What are some countries where you can be imprisoned for reading or owning a Bible?
My Friend James
Golfball Dimples on spaceships (and planes)?
What exactly is Apple Cider
Infinitely many Primes
Are there mathematical concepts that exist in the fourth dimension, but not in the third dimension?
Is there a reason effects that introduce another combat phase also create another main phase?
I won a car in a poker game
What is the difference between 「名前【なまえ】」 and 「名称【めいしょう】」?
Why did Boris Johnson call for new elections?
Why are UK MPs allowed to not vote (but it counts as a no)?
What drugs were used in England during the High Middle Ages?
Was the lunar landing site always in the same plane as the CM's orbit?
Did the US Climate Reference Network Show No New Warming Since 2005 in the US?
Get user ID from JWT (JSON web token)
Returning JSON from a PHP ScriptHow do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How do I get ASP.NET Web API to return JSON instead of XML using Chrome?Is there any JSON Web Token (JWT) example in C#?Google oAuth 2.0 (JWT token request) for Service ApplicationPython: Encode/Decode dictionary contains list to/from jsonInvalidating JSON Web TokensValidate Live.com (Microsoft account) JWT tokenRetrieving JWT from Google+ will not validateJWT (JSON Web Token) automatic prolongation of expiration
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am using the plugin to authenticate WordPress using api-rest : JWT Authentication for WP REST API
From the request to the server I get the following answer:
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbWlob3N0Lm9yZ1wvcHJ1ZWJhcyIsImlhdCI6MTU1MzcyNDM4MSwibmJmIjoxNTUzNzI0MzgxLCJleHAiOjE1NTQzMjkxODEsImRhdGEiOnsidXNlciI6eyJpZCI6IjIifX19.rgi5Q2c8RCoHRp-lJiJN8xQaOavn9T_q8cmf8v1-57o",
"user_email": "abc@test.com",
"user_nicename": "test",
"user_display_name": "Test"
So far everything works fine, but I need to know the user ID.
I have read that the token is coded in base64 and within this is the ID. Trying to decode, I see if the ID that I need is there.
In swift with this function I decode the token, but I can not get the dictionary ID.
func decode(_ token: String) -> [String: AnyObject]?
let string = token.components(separatedBy: ".")
let toDecode = string[1] as String
var stringtoDecode: String = toDecode.replacingOccurrences(of: "-", with: "+") // 62nd char of encoding
stringtoDecode = stringtoDecode.replacingOccurrences(of: "_", with: "/") // 63rd char of encoding
switch (stringtoDecode.utf16.count % 4)
case 2: stringtoDecode = "(stringtoDecode)=="
case 3: stringtoDecode = "(stringtoDecode)="
default: // nothing to do stringtoDecode can stay the same
print("")
let dataToDecode = Data(base64Encoded: stringtoDecode, options: [])
let base64DecodedString = NSString(data: dataToDecode!, encoding: String.Encoding.utf8.rawValue)
var values: [String: AnyObject]?
if let string = base64DecodedString
if let data = string.data(using: String.Encoding.utf8.rawValue, allowLossyConversion: true)
values = try! JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as? [String : AnyObject]
return values
The dictionary that returns this function is:
["iss": https://myhost.me/test, "exp": 1554235730, "nbf": 1553630930, "iat": 1553630930, "data":
user =
id = 2;
;
]
How do I get the ID from this dictionary?
json swift jwt
add a comment |
I am using the plugin to authenticate WordPress using api-rest : JWT Authentication for WP REST API
From the request to the server I get the following answer:
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbWlob3N0Lm9yZ1wvcHJ1ZWJhcyIsImlhdCI6MTU1MzcyNDM4MSwibmJmIjoxNTUzNzI0MzgxLCJleHAiOjE1NTQzMjkxODEsImRhdGEiOnsidXNlciI6eyJpZCI6IjIifX19.rgi5Q2c8RCoHRp-lJiJN8xQaOavn9T_q8cmf8v1-57o",
"user_email": "abc@test.com",
"user_nicename": "test",
"user_display_name": "Test"
So far everything works fine, but I need to know the user ID.
I have read that the token is coded in base64 and within this is the ID. Trying to decode, I see if the ID that I need is there.
In swift with this function I decode the token, but I can not get the dictionary ID.
func decode(_ token: String) -> [String: AnyObject]?
let string = token.components(separatedBy: ".")
let toDecode = string[1] as String
var stringtoDecode: String = toDecode.replacingOccurrences(of: "-", with: "+") // 62nd char of encoding
stringtoDecode = stringtoDecode.replacingOccurrences(of: "_", with: "/") // 63rd char of encoding
switch (stringtoDecode.utf16.count % 4)
case 2: stringtoDecode = "(stringtoDecode)=="
case 3: stringtoDecode = "(stringtoDecode)="
default: // nothing to do stringtoDecode can stay the same
print("")
let dataToDecode = Data(base64Encoded: stringtoDecode, options: [])
let base64DecodedString = NSString(data: dataToDecode!, encoding: String.Encoding.utf8.rawValue)
var values: [String: AnyObject]?
if let string = base64DecodedString
if let data = string.data(using: String.Encoding.utf8.rawValue, allowLossyConversion: true)
values = try! JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as? [String : AnyObject]
return values
The dictionary that returns this function is:
["iss": https://myhost.me/test, "exp": 1554235730, "nbf": 1553630930, "iat": 1553630930, "data":
user =
id = 2;
;
]
How do I get the ID from this dictionary?
json swift jwt
you can easily extract by JSON parsing from yourvaluesvar.if let user = values["data"] as [String: Any], let id = user["id"] as Int return id
– Rahul
Mar 28 at 5:14
Why do you append=at the end ofbase64string? It won't do nothingData(base64Encoded:). At least I haven't seen it resulting innilwithout=padding.
– user28434
Apr 4 at 15:45
add a comment |
I am using the plugin to authenticate WordPress using api-rest : JWT Authentication for WP REST API
From the request to the server I get the following answer:
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbWlob3N0Lm9yZ1wvcHJ1ZWJhcyIsImlhdCI6MTU1MzcyNDM4MSwibmJmIjoxNTUzNzI0MzgxLCJleHAiOjE1NTQzMjkxODEsImRhdGEiOnsidXNlciI6eyJpZCI6IjIifX19.rgi5Q2c8RCoHRp-lJiJN8xQaOavn9T_q8cmf8v1-57o",
"user_email": "abc@test.com",
"user_nicename": "test",
"user_display_name": "Test"
So far everything works fine, but I need to know the user ID.
I have read that the token is coded in base64 and within this is the ID. Trying to decode, I see if the ID that I need is there.
In swift with this function I decode the token, but I can not get the dictionary ID.
func decode(_ token: String) -> [String: AnyObject]?
let string = token.components(separatedBy: ".")
let toDecode = string[1] as String
var stringtoDecode: String = toDecode.replacingOccurrences(of: "-", with: "+") // 62nd char of encoding
stringtoDecode = stringtoDecode.replacingOccurrences(of: "_", with: "/") // 63rd char of encoding
switch (stringtoDecode.utf16.count % 4)
case 2: stringtoDecode = "(stringtoDecode)=="
case 3: stringtoDecode = "(stringtoDecode)="
default: // nothing to do stringtoDecode can stay the same
print("")
let dataToDecode = Data(base64Encoded: stringtoDecode, options: [])
let base64DecodedString = NSString(data: dataToDecode!, encoding: String.Encoding.utf8.rawValue)
var values: [String: AnyObject]?
if let string = base64DecodedString
if let data = string.data(using: String.Encoding.utf8.rawValue, allowLossyConversion: true)
values = try! JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as? [String : AnyObject]
return values
The dictionary that returns this function is:
["iss": https://myhost.me/test, "exp": 1554235730, "nbf": 1553630930, "iat": 1553630930, "data":
user =
id = 2;
;
]
How do I get the ID from this dictionary?
json swift jwt
I am using the plugin to authenticate WordPress using api-rest : JWT Authentication for WP REST API
From the request to the server I get the following answer:
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvbWlob3N0Lm9yZ1wvcHJ1ZWJhcyIsImlhdCI6MTU1MzcyNDM4MSwibmJmIjoxNTUzNzI0MzgxLCJleHAiOjE1NTQzMjkxODEsImRhdGEiOnsidXNlciI6eyJpZCI6IjIifX19.rgi5Q2c8RCoHRp-lJiJN8xQaOavn9T_q8cmf8v1-57o",
"user_email": "abc@test.com",
"user_nicename": "test",
"user_display_name": "Test"
So far everything works fine, but I need to know the user ID.
I have read that the token is coded in base64 and within this is the ID. Trying to decode, I see if the ID that I need is there.
In swift with this function I decode the token, but I can not get the dictionary ID.
func decode(_ token: String) -> [String: AnyObject]?
let string = token.components(separatedBy: ".")
let toDecode = string[1] as String
var stringtoDecode: String = toDecode.replacingOccurrences(of: "-", with: "+") // 62nd char of encoding
stringtoDecode = stringtoDecode.replacingOccurrences(of: "_", with: "/") // 63rd char of encoding
switch (stringtoDecode.utf16.count % 4)
case 2: stringtoDecode = "(stringtoDecode)=="
case 3: stringtoDecode = "(stringtoDecode)="
default: // nothing to do stringtoDecode can stay the same
print("")
let dataToDecode = Data(base64Encoded: stringtoDecode, options: [])
let base64DecodedString = NSString(data: dataToDecode!, encoding: String.Encoding.utf8.rawValue)
var values: [String: AnyObject]?
if let string = base64DecodedString
if let data = string.data(using: String.Encoding.utf8.rawValue, allowLossyConversion: true)
values = try! JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions.allowFragments) as? [String : AnyObject]
return values
The dictionary that returns this function is:
["iss": https://myhost.me/test, "exp": 1554235730, "nbf": 1553630930, "iat": 1553630930, "data":
user =
id = 2;
;
]
How do I get the ID from this dictionary?
json swift jwt
json swift jwt
asked Mar 28 at 4:48
Mario BurgaMario Burga
5164 silver badges11 bronze badges
5164 silver badges11 bronze badges
you can easily extract by JSON parsing from yourvaluesvar.if let user = values["data"] as [String: Any], let id = user["id"] as Int return id
– Rahul
Mar 28 at 5:14
Why do you append=at the end ofbase64string? It won't do nothingData(base64Encoded:). At least I haven't seen it resulting innilwithout=padding.
– user28434
Apr 4 at 15:45
add a comment |
you can easily extract by JSON parsing from yourvaluesvar.if let user = values["data"] as [String: Any], let id = user["id"] as Int return id
– Rahul
Mar 28 at 5:14
Why do you append=at the end ofbase64string? It won't do nothingData(base64Encoded:). At least I haven't seen it resulting innilwithout=padding.
– user28434
Apr 4 at 15:45
you can easily extract by JSON parsing from your
values var. if let user = values["data"] as [String: Any], let id = user["id"] as Int return id – Rahul
Mar 28 at 5:14
you can easily extract by JSON parsing from your
values var. if let user = values["data"] as [String: Any], let id = user["id"] as Int return id – Rahul
Mar 28 at 5:14
Why do you append
= at the end of base64 string? It won't do nothing Data(base64Encoded:). At least I haven't seen it resulting in nil without = padding.– user28434
Apr 4 at 15:45
Why do you append
= at the end of base64 string? It won't do nothing Data(base64Encoded:). At least I haven't seen it resulting in nil without = padding.– user28434
Apr 4 at 15:45
add a comment |
1 Answer
1
active
oldest
votes
Your code is pretty unswifty.
Basically don't use NS... classes in Swift if there is a native equivalent and a JSON dictionary is always value type ([String:Any]).
I recommend to add an Error enum, make the function can throw, decode the serialized token with Decodable and return the Token instance on success
struct Token : Decodable
let data : UserData
struct UserData : Decodable
let user : User
struct User : Decodable
let id : String
You are encouraged to keep the parameter label in the method declaration
enum TokenError : Error
case invalidJWTFormat, invalidBase64EncodedData
func decode(token: String) throws -> Token
let components = token.components(separatedBy: ".")
guard components.count == 3 else throw TokenError.invalidJWTFormat
var decodedString = components[1]
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
while decodedString.utf16.count % 4 != 0
decodedString += "="
guard let decodedData = Data(base64Encoded: decodedString) else throw TokenError.invalidBase64EncodedData
return try JSONDecoder().decode(Token.self, from: decodedData)
and call it
do
let userID = try decode(token: "eyJ0eXAi.....").data.user.id
catch print(error)
ValidJWTcontains not just> 1sections, butthreesections, no more and no less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three. Five is right out.
– user28434
Apr 4 at 15:51
@user28434 Thanks for heads-up. I updated the answer.
– vadian
Apr 4 at 15:53
And to be honest, just getting data from JWT without validating it's signature just nullifies essence of JWT. Whatever garbage payload from whatever source will do that way. And jwt.io lists like 4 different that will do most of the checks and verifications for you.
– user28434
Apr 5 at 8:47
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390350%2fget-user-id-from-jwt-json-web-token%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your code is pretty unswifty.
Basically don't use NS... classes in Swift if there is a native equivalent and a JSON dictionary is always value type ([String:Any]).
I recommend to add an Error enum, make the function can throw, decode the serialized token with Decodable and return the Token instance on success
struct Token : Decodable
let data : UserData
struct UserData : Decodable
let user : User
struct User : Decodable
let id : String
You are encouraged to keep the parameter label in the method declaration
enum TokenError : Error
case invalidJWTFormat, invalidBase64EncodedData
func decode(token: String) throws -> Token
let components = token.components(separatedBy: ".")
guard components.count == 3 else throw TokenError.invalidJWTFormat
var decodedString = components[1]
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
while decodedString.utf16.count % 4 != 0
decodedString += "="
guard let decodedData = Data(base64Encoded: decodedString) else throw TokenError.invalidBase64EncodedData
return try JSONDecoder().decode(Token.self, from: decodedData)
and call it
do
let userID = try decode(token: "eyJ0eXAi.....").data.user.id
catch print(error)
ValidJWTcontains not just> 1sections, butthreesections, no more and no less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three. Five is right out.
– user28434
Apr 4 at 15:51
@user28434 Thanks for heads-up. I updated the answer.
– vadian
Apr 4 at 15:53
And to be honest, just getting data from JWT without validating it's signature just nullifies essence of JWT. Whatever garbage payload from whatever source will do that way. And jwt.io lists like 4 different that will do most of the checks and verifications for you.
– user28434
Apr 5 at 8:47
add a comment |
Your code is pretty unswifty.
Basically don't use NS... classes in Swift if there is a native equivalent and a JSON dictionary is always value type ([String:Any]).
I recommend to add an Error enum, make the function can throw, decode the serialized token with Decodable and return the Token instance on success
struct Token : Decodable
let data : UserData
struct UserData : Decodable
let user : User
struct User : Decodable
let id : String
You are encouraged to keep the parameter label in the method declaration
enum TokenError : Error
case invalidJWTFormat, invalidBase64EncodedData
func decode(token: String) throws -> Token
let components = token.components(separatedBy: ".")
guard components.count == 3 else throw TokenError.invalidJWTFormat
var decodedString = components[1]
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
while decodedString.utf16.count % 4 != 0
decodedString += "="
guard let decodedData = Data(base64Encoded: decodedString) else throw TokenError.invalidBase64EncodedData
return try JSONDecoder().decode(Token.self, from: decodedData)
and call it
do
let userID = try decode(token: "eyJ0eXAi.....").data.user.id
catch print(error)
ValidJWTcontains not just> 1sections, butthreesections, no more and no less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three. Five is right out.
– user28434
Apr 4 at 15:51
@user28434 Thanks for heads-up. I updated the answer.
– vadian
Apr 4 at 15:53
And to be honest, just getting data from JWT without validating it's signature just nullifies essence of JWT. Whatever garbage payload from whatever source will do that way. And jwt.io lists like 4 different that will do most of the checks and verifications for you.
– user28434
Apr 5 at 8:47
add a comment |
Your code is pretty unswifty.
Basically don't use NS... classes in Swift if there is a native equivalent and a JSON dictionary is always value type ([String:Any]).
I recommend to add an Error enum, make the function can throw, decode the serialized token with Decodable and return the Token instance on success
struct Token : Decodable
let data : UserData
struct UserData : Decodable
let user : User
struct User : Decodable
let id : String
You are encouraged to keep the parameter label in the method declaration
enum TokenError : Error
case invalidJWTFormat, invalidBase64EncodedData
func decode(token: String) throws -> Token
let components = token.components(separatedBy: ".")
guard components.count == 3 else throw TokenError.invalidJWTFormat
var decodedString = components[1]
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
while decodedString.utf16.count % 4 != 0
decodedString += "="
guard let decodedData = Data(base64Encoded: decodedString) else throw TokenError.invalidBase64EncodedData
return try JSONDecoder().decode(Token.self, from: decodedData)
and call it
do
let userID = try decode(token: "eyJ0eXAi.....").data.user.id
catch print(error)
Your code is pretty unswifty.
Basically don't use NS... classes in Swift if there is a native equivalent and a JSON dictionary is always value type ([String:Any]).
I recommend to add an Error enum, make the function can throw, decode the serialized token with Decodable and return the Token instance on success
struct Token : Decodable
let data : UserData
struct UserData : Decodable
let user : User
struct User : Decodable
let id : String
You are encouraged to keep the parameter label in the method declaration
enum TokenError : Error
case invalidJWTFormat, invalidBase64EncodedData
func decode(token: String) throws -> Token
let components = token.components(separatedBy: ".")
guard components.count == 3 else throw TokenError.invalidJWTFormat
var decodedString = components[1]
.replacingOccurrences(of: "-", with: "+")
.replacingOccurrences(of: "_", with: "/")
while decodedString.utf16.count % 4 != 0
decodedString += "="
guard let decodedData = Data(base64Encoded: decodedString) else throw TokenError.invalidBase64EncodedData
return try JSONDecoder().decode(Token.self, from: decodedData)
and call it
do
let userID = try decode(token: "eyJ0eXAi.....").data.user.id
catch print(error)
edited Apr 4 at 15:52
answered Mar 28 at 5:23
vadianvadian
172k20 gold badges187 silver badges209 bronze badges
172k20 gold badges187 silver badges209 bronze badges
ValidJWTcontains not just> 1sections, butthreesections, no more and no less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three. Five is right out.
– user28434
Apr 4 at 15:51
@user28434 Thanks for heads-up. I updated the answer.
– vadian
Apr 4 at 15:53
And to be honest, just getting data from JWT without validating it's signature just nullifies essence of JWT. Whatever garbage payload from whatever source will do that way. And jwt.io lists like 4 different that will do most of the checks and verifications for you.
– user28434
Apr 5 at 8:47
add a comment |
ValidJWTcontains not just> 1sections, butthreesections, no more and no less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three. Five is right out.
– user28434
Apr 4 at 15:51
@user28434 Thanks for heads-up. I updated the answer.
– vadian
Apr 4 at 15:53
And to be honest, just getting data from JWT without validating it's signature just nullifies essence of JWT. Whatever garbage payload from whatever source will do that way. And jwt.io lists like 4 different that will do most of the checks and verifications for you.
– user28434
Apr 5 at 8:47
Valid
JWT contains not just > 1 sections, but three sections, no more and no less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three. Five is right out.– user28434
Apr 4 at 15:51
Valid
JWT contains not just > 1 sections, but three sections, no more and no less. Three shalt be the number thou shalt count, and the number of the counting shall be three. Four shalt thou not count, nor either count thou two, excepting that thou then proceed to three. Five is right out.– user28434
Apr 4 at 15:51
@user28434 Thanks for heads-up. I updated the answer.
– vadian
Apr 4 at 15:53
@user28434 Thanks for heads-up. I updated the answer.
– vadian
Apr 4 at 15:53
And to be honest, just getting data from JWT without validating it's signature just nullifies essence of JWT. Whatever garbage payload from whatever source will do that way. And jwt.io lists like 4 different that will do most of the checks and verifications for you.
– user28434
Apr 5 at 8:47
And to be honest, just getting data from JWT without validating it's signature just nullifies essence of JWT. Whatever garbage payload from whatever source will do that way. And jwt.io lists like 4 different that will do most of the checks and verifications for you.
– user28434
Apr 5 at 8:47
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55390350%2fget-user-id-from-jwt-json-web-token%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
you can easily extract by JSON parsing from your
valuesvar.if let user = values["data"] as [String: Any], let id = user["id"] as Int return id– Rahul
Mar 28 at 5:14
Why do you append
=at the end ofbase64string? It won't do nothingData(base64Encoded:). At least I haven't seen it resulting innilwithout=padding.– user28434
Apr 4 at 15:45