commit | author | age
|
3eceb5
|
1 |
// |
W |
2 |
// VKAccessToken.h |
|
3 |
// |
|
4 |
// Copyright (c) 2014 VK.com |
|
5 |
// |
|
6 |
// Permission is hereby granted, free of charge, to any person obtaining a copy of |
|
7 |
// this software and associated documentation files (the "Software"), to deal in |
|
8 |
// the Software without restriction, including without limitation the rights to |
|
9 |
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
|
10 |
// the Software, and to permit persons to whom the Software is furnished to do so, |
|
11 |
// subject to the following conditions: |
|
12 |
// |
|
13 |
// The above copyright notice and this permission notice shall be included in all |
|
14 |
// copies or substantial portions of the Software. |
|
15 |
// |
|
16 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
17 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
18 |
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
19 |
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
20 |
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
21 |
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
22 |
// |
|
23 |
// -------------------------------------------------------------------------------- |
|
24 |
// |
|
25 |
|
|
26 |
#import <Foundation/Foundation.h> |
|
27 |
#import "VKObject.h" |
|
28 |
#import "VKUser.h" |
|
29 |
|
|
30 |
/** |
|
31 |
* Represents VK API access token that used for loading API methods and other stuff. |
|
32 |
*/ |
|
33 |
@interface VKAccessToken : VKObject <NSCoding> |
|
34 |
|
|
35 |
/// String token for use in request parameters |
|
36 |
@property(nonatomic, readonly, copy) NSString *accessToken; |
|
37 |
|
|
38 |
/// Current user id for this token |
|
39 |
@property(nonatomic, readonly, copy) NSString *userId; |
|
40 |
|
|
41 |
/// User secret to sign requests (if nohttps used) |
|
42 |
@property(nonatomic, readonly, copy) NSString *secret; |
|
43 |
|
|
44 |
// Permisiions assosiated with token |
|
45 |
@property(nonatomic, readonly, copy) NSArray *permissions; |
|
46 |
|
|
47 |
// User email (if passed) |
|
48 |
@property(nonatomic, readonly, copy) NSString *email; |
|
49 |
|
|
50 |
/// Time when token expires |
|
51 |
@property(nonatomic, readonly, assign) NSInteger expiresIn; |
|
52 |
|
|
53 |
/// If user sets "Always use HTTPS" setting in his profile, it will be true |
|
54 |
@property(nonatomic, readonly, assign) BOOL httpsRequired; |
|
55 |
|
|
56 |
/// Indicates time of token creation |
|
57 |
@property(nonatomic, readonly, assign) NSTimeInterval created; |
|
58 |
|
|
59 |
/// Contains basic current user information. Available after delegate method -[VKSdkDelegate vkSdkAuthorizationStateUpdatedWithResult:] called |
|
60 |
@property(nonatomic, readonly, strong) VKUser *localUser; |
|
61 |
|
|
62 |
/** |
|
63 |
Retrieve token from key-value query string |
|
64 |
@param urlString string that contains URL-query part with token. E.g. access_token=ffffff&expires_in=0... |
|
65 |
@return parsed token |
|
66 |
*/ |
|
67 |
+ (instancetype)tokenFromUrlString:(NSString *)urlString; |
|
68 |
|
|
69 |
/** |
|
70 |
Create token with existing properties |
|
71 |
@param accessToken token string |
|
72 |
@param secret secret |
|
73 |
@param userId user id |
|
74 |
@return new token |
|
75 |
*/ |
|
76 |
+ (instancetype)tokenWithToken:(NSString *)accessToken secret:(NSString *)secret userId:(NSString *)userId; |
|
77 |
|
|
78 |
/** |
|
79 |
Retrieve token from user defaults. Token must be saved to defaults with saveTokenToDefaults method |
|
80 |
@param defaultsKey path to file with saved token |
|
81 |
@return parsed token |
|
82 |
*/ |
|
83 |
+ (instancetype)savedToken:(NSString *)defaultsKey; |
|
84 |
|
|
85 |
/** |
|
86 |
Save token into user defaults by specified key |
|
87 |
@param defaultsKey key for defaults |
|
88 |
*/ |
|
89 |
- (void)saveTokenToDefaults:(NSString *)defaultsKey; |
|
90 |
|
|
91 |
/// Return YES if token has expired |
|
92 |
- (BOOL)isExpired; |
|
93 |
|
|
94 |
/** |
|
95 |
Remove token from storage |
|
96 |
|
|
97 |
@param service Access token storage key name |
|
98 |
*/ |
|
99 |
+ (void)delete:(NSString *)service; |
|
100 |
|
|
101 |
@end |
|
102 |
|
|
103 |
/** |
|
104 |
* This is mutable version of VKAccessToken. You should never use this class directly |
|
105 |
*/ |
|
106 |
@interface VKAccessTokenMutable : VKAccessToken |
|
107 |
@property(nonatomic, readwrite, copy) NSString *accessToken; |
|
108 |
@property(nonatomic, readwrite, copy) NSString *userId; |
|
109 |
@property(nonatomic, readwrite, copy) NSString *secret; |
|
110 |
@property(nonatomic, readwrite, copy) NSArray *permissions; |
|
111 |
@property(nonatomic, readwrite, assign) BOOL httpsRequired; |
|
112 |
@property(nonatomic, readwrite, assign) NSInteger expiresIn; |
|
113 |
@property(nonatomic, readwrite, strong) VKUser *localUser; |
|
114 |
@end |