Jsonwebtoken.swift

Swift implementation of JSON Web Token (JWT).
Alternatives To Jsonwebtoken.swift
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Next Auth18,7992122615 hours ago650July 25, 2023305iscTypeScript
Authentication for the Web.
Jwt7,0606,8175354 days ago53February 25, 20237bsd-3-clausePHP
A simple library to work with JSON Web Token and JSON Web Signature
Java Jwt5,4101,9024026 days ago58March 31, 20234mitJava
Java implementation of JSON Web Token (JWT)
Pyjwt4,6929,4432,1929 days ago48July 18, 202318mitPython
JSON Web Token implementation in Python
Express Jwt4,39812,5388233 days ago71February 06, 202354mitTypeScript
connect/express middleware that validates a JsonWebToken (JWT) and set the req.user with the attributes
Jwt_tool4,179
3 months ago45gpl-3.0Python
:snake: A toolkit for testing, tweaking and cracking JSON Web Tokens
Learn Json Web Tokens4,16428 months ago3April 15, 201920mitJavaScript
:closed_lock_with_key: Learn how to use JSON Web Token (JWT) to secure your next Web App! (Tutorial/Example with Tests!!)
Iot Technical Guide3,552
19 days ago13apache-2.0Java
:honeybee: IoT Technical Guide --- 从零搭建高性能物联网平台及物联网解决方案和Thingsboard源码分析 :sparkles: :sparkles: :sparkles: (IoT Platform, SaaS, MQTT, CoAP, HTTP, Modbus, OPC, WebSocket, 物模型,Protobuf, PostgreSQL, MongoDB, Spring Security, OAuth2, RuleEngine, Kafka, Docker)
Guardian3,3236852912 days ago51November 24, 20225mitElixir
Elixir Authentication
Cli3,2351214 days ago313July 18, 2023125apache-2.0Go
🧰 A zero trust swiss army knife for working with X509, OAuth, JWT, OATH OTP, etc.
Alternatives To Jsonwebtoken.swift
Select To Compare


Alternative Project Comparisons
Readme

JSON Web Token

Build Status

Swift implementation of JSON Web Token.

Installation

Swift Pacakage Manager is the recommended installation method for JSONWebToken, CocoaPods is also supported.

pod 'JSONWebToken'

NOTE: Carthage may be supported, however support will not be provided for this installation method, use at your own risk if you know how it works.

Usage

import JWT

Encoding a claim

JWT.encode(claims: ["my": "payload"], algorithm: .hs256("secret".data(using: .utf8)!))

Encoding a claim set

var claims = ClaimSet()
claims.issuer = "fuller.li"
claims.issuedAt = Date()
claims["custom"] = "Hi"

JWT.encode(claims: claims, algorithm: .hs256("secret".data(using: .utf8)!))

Building a JWT with the builder pattern

JWT.encode(.hs256("secret".data(using: .utf8))) { builder in
  builder.issuer = "fuller.li"
  builder.issuedAt = Date()
  builder["custom"] = "Hi"
}

Decoding a JWT

When decoding a JWT, you must supply one or more algorithms and keys.

do {
  let claims: ClaimSet = try JWT.decode("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.2_8pWJfyPup0YwOXK7g9Dn0cF1E3pdn299t4hSeJy5w", algorithm: .hs256("secret".data(using: .utf8)!))
  print(claims)
} catch {
  print("Failed to decode JWT: \(error)")
}

When the JWT may be signed with one out of many algorithms or keys:

try JWT.decode("eyJh...5w", algorithms: [
  .hs256("secret".data(using: .utf8)!),
  .hs256("secret2".data(using: .utf8)!),
  .hs512("secure".data(using: .utf8)!)
])

You might also want to give your iat, exp and nbf checks some kind of leeway to account for skewed clocks. You can do this by passing a leeway parameter like this:

try JWT.decode("eyJh...5w", algorithm: .hs256("secret".data(using: .utf8)!), leeway: 10)

Supported claims

The library supports validating the following claims:

  • Issuer (iss) Claim
  • Expiration Time (exp) Claim
  • Not Before (nbf) Claim
  • Issued At (iat) Claim
  • Audience (aud) Claim

Algorithms

This library supports the following algorithms:

  • none - Unsecured JWTs
  • hs256 - HMAC using SHA-256 hash algorithm (default)
  • hs384 - HMAC using SHA-384 hash algorithm
  • hs512 - HMAC using SHA-512 hash algorithm

License

JSONWebToken is licensed under the BSD license. See LICENSE for more info.

Popular Jwt Projects
Popular Token Projects
Popular Security Categories

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Swift
Json
Algorithms
Token
Jwt
Hmac