Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hzalaz committed Sep 16, 2015
1 parent 739e249 commit b39e4f4
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 42 deletions.
55 changes: 55 additions & 0 deletions JWTDecode.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,60 @@
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=8&amp;CharacterRangeLoc=397&amp;EndingColumnNumber=13&amp;EndingLineNumber=10&amp;StartingColumnNumber=5&amp;StartingLineNumber=10&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=13&amp;CharacterRangeLoc=410&amp;EndingColumnNumber=18&amp;EndingLineNumber=11&amp;StartingColumnNumber=5&amp;StartingLineNumber=11&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=10&amp;CharacterRangeLoc=382&amp;EndingColumnNumber=15&amp;EndingLineNumber=9&amp;StartingColumnNumber=5&amp;StartingLineNumber=9&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=12&amp;CharacterRangeLoc=430&amp;EndingColumnNumber=17&amp;EndingLineNumber=14&amp;StartingColumnNumber=5&amp;StartingLineNumber=14&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=11&amp;CharacterRangeLoc=447&amp;EndingColumnNumber=16&amp;EndingLineNumber=15&amp;StartingColumnNumber=5&amp;StartingLineNumber=15&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=14&amp;CharacterRangeLoc=463&amp;EndingColumnNumber=19&amp;EndingLineNumber=16&amp;StartingColumnNumber=5&amp;StartingLineNumber=16&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=10&amp;CharacterRangeLoc=482&amp;EndingColumnNumber=15&amp;EndingLineNumber=17&amp;StartingColumnNumber=5&amp;StartingLineNumber=17&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=13&amp;CharacterRangeLoc=497&amp;EndingColumnNumber=18&amp;EndingLineNumber=18&amp;StartingColumnNumber=5&amp;StartingLineNumber=18&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=12&amp;CharacterRangeLoc=515&amp;EndingColumnNumber=17&amp;EndingLineNumber=19&amp;StartingColumnNumber=5&amp;StartingLineNumber=19&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=13&amp;CharacterRangeLoc=532&amp;EndingColumnNumber=18&amp;EndingLineNumber=20&amp;StartingColumnNumber=5&amp;StartingLineNumber=20&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
<LoggerValueHistoryTimelineItem
documentLocation = "#CharacterRangeLen=6&amp;CharacterRangeLoc=556&amp;EndingColumnNumber=15&amp;EndingLineNumber=23&amp;StartingColumnNumber=9&amp;StartingLineNumber=23&amp;Timestamp=464124874.199094"
selectedRepresentationIndex = "0"
shouldTrackSuperviewWidth = "NO">
</LoggerValueHistoryTimelineItem>
</TimelineItems>
</Timeline>
2 changes: 1 addition & 1 deletion JWTDecode/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.3.2</string>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
2 changes: 1 addition & 1 deletion JWTDecodeTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>0.3.2</string>
<string>1.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
Expand Down
101 changes: 61 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# JWTDecode
# JWTDecode.swift

[![CI Status](http://img.shields.io/travis/auth0/JWTDecode.swift.svg?style=flat-square)](https://travis-ci.org/auth0/JWTDecode.swift)
[![Version](https://img.shields.io/cocoapods/v/JWTDecode.svg?style=flat-square)](http://cocoadocs.org/docsets/JWTDecode)
Expand All @@ -8,11 +8,11 @@

This library will help you check [JWT](http://jwt.io/) payload

> This library doesn't validate the token, any well formed JWT can be decoded from Base64.
> This library doesn't validate the token, any well formed JWT can be decoded from Base64Url.
## Requirements

iOS 8+
iOS 8+ and at least Xcode 7 (for Swift 2.0).

## Installation

Expand All @@ -22,7 +22,7 @@ JWTDecode is available through [CocoaPods](http://cocoapods.org). To install
it, simply add the following line to your Podfile:

```ruby
pod "JWTDecode", '~> 0.3'
pod "JWTDecode", '~> 1.0'
```

###Carthage
Expand All @@ -35,63 +35,84 @@ github "auth0/JWTDecode.swift"

###Manual installation

Download and add `JWTDecode.swift` to your project in Xcode.
Download `JWTDecode.framework` from [Releases](/releases) and add it to your project in Xcode.

##JWTDecoder

###Decoding JWT token
##Usage

```objc
@import JWTDecode;

NSString *jwt = ...; //Your JWT to decode
NSError *error;
JWTDecoder *decoder = [[JWTDecoder alloc] initWithJwt:jwt];
NSDictionary *payload = [decoder payloadWithError:&error]];
NSLog(@"JWT payload is %@", payload);
```
Just import the framework

```swift
import JWTDecode
let jwt = ... //Your JWT to decode
let payload = A0JWTDecode.payload(jwt: jwt)
println("JWT payload is \(payload)")
```

###Get JWT token expiration date

```objc
@import JWTDecode;
and decode the token

NSString *jwt = ...; //Your JWT to decode
JWTDecoder *decoder = [[JWTDecoder alloc] initWithJwt:jwt];
NSLog(@"JWT expire date is %@", decoder.expireDate);
```swift
let jwt = try decode(token)
```

### JWT parts

####Header dictionary
```swift
import JWTDecode
jwt.header
```

let jwt = ... //Your JWT to decode
let expireDate = JWTDecode.expireDate(jwt: jwt)
println("JWT expire date is \(expireDate)")
####Claims in token body
```swift
jwt.body
```

###Check if JWT token is expired
####Token signature
```swift
jwt.signature
```

```objc
@import JWTDecode;
### Registered Claims

NSString *jwt = ...; //Your JWT to decode
JWTDecoder *decoder = [[JWTDecoder alloc] initWithJwt:jwt];
BOOL expired = decoder.expired;
* "aud" (Audience)
```swift
jwt.audience
```
* "sub" (Subject)
```swift
jwt.subject
```
* "jti" (JWT ID)
```swift
jwt.identifier
```
* "iss" (Issuer)
```swift
jwt.issuer
```
* "nbf" (Not Before)
```swift
jwt.notBefore
```
* "iat" (Issued At)
```swift
jwt.issuedAt
```
* "exp" (Expiration Time)
```swift
jwt.expiresAt
```

### Custom Claims
If we also have our custom claims we can retrive them calling `claim<T>(name: String) -> T?` where `T` is the value type of the claim, e.g.: a `String`

```swift
import JWTDecode
let custom: String? = jwt.claim("email")
```

let jwt = ... //Your JWT to decode
let expired = A0JWTDecode.expired(jwt: jwt)
### Error Handling
If the token is invalid an `NSError` will be thrown from the `decode(token)` function.
```swift
catch let error as NSError {
error.localizedDescription
}
```

## What is Auth0?
Expand Down

0 comments on commit b39e4f4

Please sign in to comment.