Add OIDTVTokenRequest class · openid/AppAuth-iOS@66da408 · GitHub
Skip to content

Commit 66da408

Browse files
authored
Add OIDTVTokenRequest class
Adds OIDTVTokenRequest class, which is a subclass of OIDTokenRequest, to better adhere to the [RFC for TV authentication](https://tools.ietf.org/html/rfc8628#section-3.4). This adds the required `device_code` property which is sent in the request body, which differs from the `code` property for the authorization code in the parent class. Additionally, the grant type for TV authorization is hard-coded in, and several unused fields are dropped from the initializer and body request code.
1 parent ecd9f2e commit 66da408

5 files changed

Lines changed: 281 additions & 10 deletions

File tree

‎AppAuth.xcodeproj/project.pbxproj‎

Lines changed: 8 additions & 0 deletions

‎Source/AppAuthCore/OIDTokenRequest.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ NS_ASSUME_NONNULL_BEGIN
152152
additionalParameters:(nullable NSDictionary<NSString *, NSString *> *)additionalParameters
153153
NS_DESIGNATED_INITIALIZER;
154154

155+
/*! @brief Designated initializer for NSSecureCoding.
156+
@param aDecoder Unarchiver object to decode
157+
*/
158+
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
159+
155160
/*! @brief Constructs an @c NSURLRequest representing the token request.
156161
@return An @c NSURLRequest representing the token request.
157162
*/

‎Source/AppAuthCore/OIDTokenRequest.m‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,21 @@ - (instancetype)initWithCoder:(NSCoder *)aDecoder {
177177
NSDictionary *additionalParameters =
178178
[aDecoder decodeObjectOfClasses:additionalParameterCodingClasses
179179
forKey:kAdditionalParametersKey];
180-
self = [self initWithConfiguration:configuration
181-
grantType:grantType
182-
authorizationCode:code
183-
redirectURL:redirectURL
184-
clientID:clientID
185-
clientSecret:clientSecret
186-
scope:scope
187-
refreshToken:refreshToken
188-
codeVerifier:codeVerifier
189-
additionalParameters:additionalParameters];
180+
181+
self = [super init];
182+
if (self) {
183+
_configuration = [configuration copy];
184+
_grantType = [grantType copy];
185+
_authorizationCode = [code copy];
186+
_redirectURL = [redirectURL copy];
187+
_clientID = [clientID copy];
188+
_clientSecret = [clientSecret copy];
189+
_scope = [scope copy];
190+
_refreshToken = [refreshToken copy];
191+
_codeVerifier = [codeVerifier copy];
192+
_additionalParameters =
193+
[[NSDictionary alloc] initWithDictionary:additionalParameters copyItems:YES];
194+
}
190195
return self;
191196
}
192197

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*! @file OIDTVTokenRequest.h
2+
@brief AppAuth iOS SDK
3+
@copyright
4+
Copyright 2020 Google Inc.
5+
@copydetails
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
#import "OIDTokenRequest.h"
20+
21+
#import <Foundation/Foundation.h>
22+
23+
@class OIDServiceConfiguration;
24+
@class OIDTVServiceConfiguration;
25+
26+
NS_ASSUME_NONNULL_BEGIN
27+
28+
@interface OIDTVTokenRequest : OIDTokenRequest
29+
30+
/*! @brief The device code received from the authorization server.
31+
@remarks device_code
32+
@see https://tools.ietf.org/html/rfc8628#section-3.4
33+
*/
34+
@property(nonatomic, readonly) NSString *deviceCode;
35+
36+
/*! @internal
37+
@brief Unavailable. Please use
38+
@c initWithConfiguration:deviceCode:clientID:clientSecret:additionalParameters:
39+
or @c initWithCoder:.
40+
*/
41+
- (instancetype)init NS_UNAVAILABLE;
42+
43+
/*! @internal
44+
@brief Unavailable. Please use
45+
@c initWithConfiguration:deviceCode:clientID:clientSecret:additionalParameters:
46+
or @c initWithCoder:.
47+
*/
48+
- (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
49+
grantType:(NSString *)grantType
50+
authorizationCode:(nullable NSString *)code
51+
redirectURL:(nullable NSURL *)redirectURL
52+
clientID:(NSString *)clientID
53+
clientSecret:(nullable NSString *)clientSecret
54+
scopes:(nullable NSArray<NSString *> *)scopes
55+
refreshToken:(nullable NSString *)refreshToken
56+
codeVerifier:(nullable NSString *)codeVerifier
57+
additionalParameters:
58+
(nullable NSDictionary<NSString *, NSString *> *)
59+
additionalParameters NS_UNAVAILABLE;
60+
61+
/*! @internal
62+
@brief Unavailable. Please use
63+
@c initWithConfiguration:deviceCode:clientID:clientSecret:additionalParameters:
64+
or @c initWithCoder:.
65+
*/
66+
- (instancetype)initWithConfiguration:(OIDServiceConfiguration *)configuration
67+
grantType:(NSString *)grantType
68+
authorizationCode:(nullable NSString *)code
69+
redirectURL:(nullable NSURL *)redirectURL
70+
clientID:(NSString *)clientID
71+
clientSecret:(nullable NSString *)clientSecret
72+
scope:(nullable NSString *)scope
73+
refreshToken:(nullable NSString *)refreshToken
74+
codeVerifier:(nullable NSString *)codeVerifier
75+
additionalParameters:
76+
(nullable NSDictionary<NSString *, NSString *> *)
77+
additionalParameters NS_UNAVAILABLE;
78+
79+
/*! @brief Designated initializer.
80+
@param configuration The service's configuration.
81+
@param deviceCode The device verification code received from the authorization server.
82+
@param clientID The client identifier.
83+
@param clientSecret The client secret (nullable).
84+
@param additionalParameters The client's additional token request parameters.
85+
*/
86+
- (instancetype)initWithConfiguration:(OIDTVServiceConfiguration *)configuration
87+
deviceCode:(NSString *)deviceCode
88+
clientID:(NSString *)clientID
89+
clientSecret:(nullable NSString *)clientSecret
90+
additionalParameters:(nullable NSDictionary<NSString *, NSString *> *)
91+
additionalParameters
92+
NS_DESIGNATED_INITIALIZER;
93+
94+
/*! @brief Designated initializer for NSSecureCoding.
95+
@param aDecoder Unarchiver object to decode
96+
*/
97+
- (instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
98+
99+
@end
100+
101+
NS_ASSUME_NONNULL_END
Lines changed: 152 additions & 0 deletions

0 commit comments

Comments
 (0)