This repository was archived by the owner on Feb 16, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathHawkAuth.h
89 lines (62 loc) · 2.34 KB
/
HawkAuth.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//
// HawkAuth.h
// Hawk
//
// Created by Jesse Stuart on 8/9/13.
// nonatomicright (c) 2013 Tent. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "HawkCredentials.h"
#import "HawkError.h"
typedef NS_ENUM(NSUInteger, HawkAuthType) {
HawkAuthTypeHeader,
HawkAuthTypeResponse,
HawkAuthTypeBewit
};
@interface HawkAuth : NSObject
@property (nonatomic) HawkCredentials *credentials;
@property (nonatomic) NSString *method;
@property (nonatomic) NSString *requestUri;
@property (nonatomic) NSString *host;
@property (nonatomic) NSUInteger port;
@property (nonatomic) NSDate *timestamp;
@property (nonatomic) NSString *nonce;
@property (nonatomic) NSString *ext;
@property (nonatomic) NSString *app;
@property (nonatomic) NSString *dlg;
@property (nonatomic) NSString *payload;
@property (nonatomic) NSString *contentType;
@property (nonatomic) NSString *digest;
@property (nonatomic) NSString *hmac;
#pragma mark -
// Returns an instance of CryptoProxy using self.credentials.algorithm
- (CryptoProxy *)cryptoProxy;
// Returns input string for hmac functions
- (NSString *)normalizedStringWithType:(HawkAuthType)type;
// Returns input string for hash digest function
- (NSString *)normalizedPayloadString;
// Sets and returns hash property
- (NSString *)payloadHash;
// Sets and returns hmac property
- (NSString *)hmacWithType:(HawkAuthType)type;
// Returns hmac for timestamp skew header
- (NSString *)timestampSkewHmac;
- (NSString *)bewit;
#pragma mark -
- (NSString *)requestHeader;
- (NSString *)responseHeader;
- (NSString *)timestampSkewHeader;
#pragma mark -
// Parses header attributes
- (NSDictionary *)parseAuthorizationHeader:(NSString *)header;
// Returns an instance of HawkError if invalid or nil if valid
// Sets self.credentials if valid
// self.nonce, self.timestamp, and self.app are set with values from header when valid hawk id
// credentialsLookup(<hawk id>) block should return an instance of HawkCredentials or nil
- (HawkError *)validateRequestHeader:(NSString *)header
credentialsLookup:(HawkCredentials *(^)(NSString *hawkId))credentialsLookup;
- (HawkError *)validateResponseHeader:(NSString *)header;
- (HawkError *)validateBewit:(NSString *)bewit
credentialsLookup:(HawkCredentials *(^)(NSString *hawkId))credentialsLookup
serverTime:(NSDate *)serverTime;
@end