Skip to content

NKJWT/NKJWT

Repository files navigation

pod version pod license pod platform JWT specifications support

NKJWT

Contents:

Why NKJWT?

JWT (JSON Web Token) is an amazing technology, which makes network / API integration extremely easy and fast. This library allows you to get all benefits of JWT with only a few lines of code.

User Guide

Installation

Add to your Podfile:

pod 'NKJWT', '~> 0.1'

Verifying Token

NSString *token = @"xxxxxxxxxxxx";
NKJWT *jwt = [[NKJWT alloc] initWithJWT:token];
isValid = [jwt verifyWithKey:key];

or if you do not prefer stateless expressions:

NSString *token = @"xxxxxxxxxxxx";
NKJWT *jwt = [[NKJWT alloc] initWithJWT:token];
[jwt setKey:key];
isValid = [jwt verify];

Getting Payload from token

NKJWT *jwt = [[NKJWT alloc] initWithJWT:token];
isValid = [jwt verifyWithKey:key];
NSDictionary *payload = jwt.payload;

Creating token

NKJWT *jwt = [[NKJWT alloc] initWithPayload:payloadDictionary];

Signing and getting signed token

NKJWT *jwt = [[NKJWT alloc] initWithPayload:payloadDictionary];
[jwt signWithKey:key];
NSString *token = [jwt token];

or without stateless expressions:

NKJWT *jwt = [[NKJWT alloc] initWithPayload:payloadDictionary];
[jwt setKey:key];
[jwt sign];
NSString *token = [jwt token];

Updating payload

NKJWT *jwt = [[NKJWT alloc] initWithPayload:payloadDictionary];
[jwt signWithKey:key];
NSString *token = [jwt token];

[jwt setPayload:newPayloadDictionary];
[jwt signWithKey:key];
NSString *newToken = [jwt token];