Skip to content

Commit

Permalink
Rename TVAuthorizationEndpoint to deviceAuthorizationEndpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
soule authored Aug 14, 2020
1 parent 8993d43 commit 88136c3
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#import <AppAuth/AppAuthTV.h>

/*! @brief Indicates whether YES to discover endpoints from @c kIssuer or NO to use the
@c kTVAuthorizationEndpoint, @c kTokenEndpoint, and @c kUserInfoEndpoint values defined
@c kDeviceAuthorizationEndpoint, @c kTokenEndpoint, and @c kUserInfoEndpoint values defined
below.
*/
static BOOL const shouldDiscoverEndpoints = YES;
Expand All @@ -41,7 +41,7 @@

/*! @brief Device authorization endpoint.
*/
static NSString *const kTVAuthorizationEndpoint = @"https://www.example.com/device";
static NSString *const kDeviceAuthorizationEndpoint = @"https://www.example.com/device";

/*! @brief Token endpoint.
*/
Expand Down Expand Up @@ -99,8 +99,8 @@ - (void)verifyConfig {
"Instructions: "
"https://github.com/openid/AppAuth-iOS/blob/master/Examples/Example-tvOS/README.md");
} else {
NSAssert(![kTVAuthorizationEndpoint isEqualToString:@"https://www.example.com/device"],
@"Update kTVAuthorizationEndpoint with your own TV authorization endpoint. "
NSAssert(![kDeviceAuthorizationEndpoint isEqualToString:@"https://www.example.com/device"],
@"Update kDeviceAuthorizationEndpoint with your own device authorization endpoint. "
"Instructions: "
"https://github.com/openid/AppAuth-iOS/blob/master/Examples/Example-tvOS/README.md");

Expand Down Expand Up @@ -155,12 +155,12 @@ - (IBAction)signin:(id)sender {
[self performAuthorizationWithConfiguration:configuration];
}];
} else {
NSURL *TVAuthorizationEndpoint = [NSURL URLWithString:kTVAuthorizationEndpoint];
NSURL *deviceAuthorizationEndpoint = [NSURL URLWithString:kDeviceAuthorizationEndpoint];
NSURL *tokenEndpoint = [NSURL URLWithString:kTokenEndpoint];

OIDTVServiceConfiguration *configuration =
[[OIDTVServiceConfiguration alloc] initWithTVAuthorizationEndpoint:TVAuthorizationEndpoint
tokenEndpoint:tokenEndpoint];
OIDTVServiceConfiguration *configuration = [[OIDTVServiceConfiguration alloc]
initWithDeviceAuthorizationEndpoint:deviceAuthorizationEndpoint
tokenEndpoint:tokenEndpoint];

// Perform authorization flow
[self performAuthorizationWithConfiguration:configuration];
Expand Down
2 changes: 1 addition & 1 deletion Source/AppAuthTV/OIDTVAuthorizationRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ - (NSURLRequest *)URLRequest {
OIDTVServiceConfiguration *tvConfiguration = (OIDTVServiceConfiguration *)self.configuration;

NSMutableURLRequest *URLRequest =
[[NSURLRequest requestWithURL:tvConfiguration.TVAuthorizationEndpoint] mutableCopy];
[[NSURLRequest requestWithURL:tvConfiguration.deviceAuthorizationEndpoint] mutableCopy];
URLRequest.HTTPMethod = kHTTPPost;
[URLRequest setValue:kHTTPContentTypeHeaderValue forHTTPHeaderField:kHTTPContentTypeHeaderKey];
NSString *bodyString = [query URLEncodedParameters];
Expand Down
15 changes: 8 additions & 7 deletions Source/AppAuthTV/OIDTVServiceConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface OIDTVServiceConfiguration : OIDServiceConfiguration

/*! @brief The TV authorization endpoint URI.
/*! @brief The device authorization endpoint URI.
*/
@property(nonatomic, readonly) NSURL *TVAuthorizationEndpoint;
@property(nonatomic, readonly) NSURL *deviceAuthorizationEndpoint;

/*! @internal
@brief Unavailable. Please use
@c initWithTVAuthorizationEndpoint:tokenEndpoint:
@c initWithDeviceAuthorizationEndpoint:tokenEndpoint:
*/
- (instancetype)init NS_UNAVAILABLE;

/*! @internal
@brief Unavailable. Please use
@c initWithTVAuthorizationEndpoint:tokenEndpoint:
@c initWithDeviceAuthorizationEndpoint:tokenEndpoint:
*/
- (instancetype)initWithAuthorizationEndpoint:(NSURL *)authorizationEndpoint
tokenEndpoint:(NSURL *)tokenEndpoint NS_UNAVAILABLE;
Expand All @@ -49,11 +49,12 @@ NS_ASSUME_NONNULL_BEGIN
NS_DESIGNATED_INITIALIZER;

/*! @brief Designated initializer.
@param TVAuthorizationEndpoint The TV authorization endpoint URI.
@param deviceAuthorizationEndpoint The device authorization endpoint URI.
@param tokenEndpoint The token exchange and refresh endpoint URI.
*/
- (instancetype)initWithTVAuthorizationEndpoint:(NSURL *)TVAuthorizationEndpoint
tokenEndpoint:(NSURL *)tokenEndpoint NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithDeviceAuthorizationEndpoint:(NSURL *)deviceAuthorizationEndpoint
tokenEndpoint:(NSURL *)tokenEndpoint
NS_DESIGNATED_INITIALIZER;

@end

Expand Down
28 changes: 14 additions & 14 deletions Source/AppAuthTV/OIDTVServiceConfiguration.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
#import "OIDDefines.h"
#import "OIDServiceDiscovery.h"

/*! @brief The key for the @c TVAuthorizationEndpoint property.
/*! @brief The key for the @c deviceAuthorizationEndpoint property.
*/
static NSString *const kTVAuthorizationEndpointKey = @"TVAuthorizationEndpoint";
static NSString *const kDeviceAuthorizationEndpointKey = @"deviceAuthorizationEndpoint";

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -39,11 +39,11 @@ - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIAL
@implementation OIDTVServiceConfiguration

- (instancetype)init
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithTVAuthorizationEndpoint:tokenEndpoint:))
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithDeviceAuthorizationEndpoint:tokenEndpoint:))

- (instancetype)initWithAuthorizationEndpoint:(NSURL *)authorizationEndpoint
tokenEndpoint:(NSURL *)tokenEndpoint
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithTVAuthorizationEndpoint:tokenEndpoint:))
OID_UNAVAILABLE_USE_INITIALIZER(@selector(initWithDeviceAuthorizationEndpoint:tokenEndpoint:))

- (instancetype)initWithDiscoveryDocument:(OIDServiceDiscovery *)discoveryDocument {
self = [super initWithDiscoveryDocument:discoveryDocument];
Expand All @@ -53,18 +53,18 @@ - (instancetype)initWithDiscoveryDocument:(OIDServiceDiscovery *)discoveryDocume
NSLog(@"Warning: Discovery document used to initialize %@ "
@"does not contain device authorization endpoint.", self);
} else {
_TVAuthorizationEndpoint = [discoveryDocument.deviceAuthorizationEndpoint copy];
_deviceAuthorizationEndpoint = [discoveryDocument.deviceAuthorizationEndpoint copy];
}
}
return self;
}

- (instancetype)initWithTVAuthorizationEndpoint:(NSURL *)TVAuthorizationEndpoint
tokenEndpoint:(NSURL *)tokenEndpoint {
- (instancetype)initWithDeviceAuthorizationEndpoint:(NSURL *)deviceAuthorizationEndpoint
tokenEndpoint:(NSURL *)tokenEndpoint {
self = [super initWithAuthorizationEndpoint:[[NSURL alloc] initWithString:@""]
tokenEndpoint:tokenEndpoint];
if (self) {
_TVAuthorizationEndpoint = [TVAuthorizationEndpoint copy];
_deviceAuthorizationEndpoint = [deviceAuthorizationEndpoint copy];
}
return self;
}
Expand All @@ -78,25 +78,25 @@ + (BOOL)supportsSecureCoding {
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
NSURL *TVAuthorizationEndpoint = [aDecoder decodeObjectOfClass:[NSURL class]
forKey:kTVAuthorizationEndpointKey];
_TVAuthorizationEndpoint = TVAuthorizationEndpoint;
NSURL *deviceAuthorizationEndpoint =
[aDecoder decodeObjectOfClass:[NSURL class] forKey:kDeviceAuthorizationEndpointKey];
_deviceAuthorizationEndpoint = deviceAuthorizationEndpoint;
}
return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder {
[super encodeWithCoder:aCoder];
[aCoder encodeObject:_TVAuthorizationEndpoint forKey:kTVAuthorizationEndpointKey];
[aCoder encodeObject:_deviceAuthorizationEndpoint forKey:kDeviceAuthorizationEndpointKey];
}

#pragma mark - description

- (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, TVAuthorizationEndpoint: %@ tokenEndpoint: %@>",
return [NSString stringWithFormat:@"<%@: %p, deviceAuthorizationEndpoint: %@ tokenEndpoint: %@>",
NSStringFromClass([self class]),
(void *)self,
_TVAuthorizationEndpoint,
_deviceAuthorizationEndpoint,
self.tokenEndpoint];
}

Expand Down
8 changes: 4 additions & 4 deletions UnitTests/AppAuthTV/OIDTVAuthorizationRequestTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ NS_ASSUME_NONNULL_BEGIN
- (void)testInitializer;

/*! @brief Tests the @c NSCopying implementation by round-tripping an instance through the copying
* process and checking to make sure the source and destination both contain the
* @c TVAuthorizationEndpoint
* process and checking to make sure the source and destination both contain the
* @c deviceAuthorizationEndpoint
*/
- (void)testCopying;

/*! @brief Tests the @c NSSecureCoding implementation by round-tripping an instance through the
* coding process and checking to make sure the source and destination both contain the
* @c TVAuthorizationEndpoint
* coding process and checking to make sure the source and destination both contain the
* @c deviceAuthorizationEndpoint
*/
- (void)testSecureCoding;

Expand Down
46 changes: 23 additions & 23 deletions UnitTests/AppAuthTV/OIDTVAuthorizationRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu"

/*! @brief Test value for the @c TVAuthorizationEndpoint property.
/*! @brief Test value for the @c deviceAuthorizationEndpoint property.
*/
static NSString *const kTestTVAuthorizationEndpoint = @"https://www.example.com/device/code";
static NSString *const kTestDeviceAuthorizationEndpoint = @"https://www.example.com/device/code";

/*! @brief Test value for the @c tokenEndpoint property.
*/
Expand Down Expand Up @@ -89,10 +89,10 @@ @implementation OIDTVAuthorizationRequestTests

- (OIDTVServiceConfiguration *)testServiceConfiguration {
NSURL *tokenEndpoint = [NSURL URLWithString:kTestTokenEndpoint];
NSURL *TVAuthorizationEndpoint = [NSURL URLWithString:kTestTVAuthorizationEndpoint];
NSURL *deviceAuthorizationEndpoint = [NSURL URLWithString:kTestDeviceAuthorizationEndpoint];

OIDTVServiceConfiguration *configuration =
[[OIDTVServiceConfiguration alloc] initWithTVAuthorizationEndpoint:TVAuthorizationEndpoint
[[OIDTVServiceConfiguration alloc] initWithDeviceAuthorizationEndpoint:deviceAuthorizationEndpoint
tokenEndpoint:tokenEndpoint];
return configuration;
}
Expand Down Expand Up @@ -131,22 +131,22 @@ - (void)testInitializer {
scopes:testScopes
additionalParameters:testAdditionalParameters];

NSURL *authRequestTVAuthorizationEndpoint =
((OIDTVServiceConfiguration *)authRequest.configuration).TVAuthorizationEndpoint;
NSURL *authRequestDeviceAuthorizationEndpoint =
((OIDTVServiceConfiguration *)authRequest.configuration).deviceAuthorizationEndpoint;

XCTAssertEqualObjects(authRequest.clientID, kTestClientID);
XCTAssertEqualObjects(authRequest.clientSecret, kTestClientSecret);
XCTAssertEqualObjects(authRequest.scope, testScopeString);
XCTAssertEqualObjects(authRequest.additionalParameters, testAdditionalParameters);
XCTAssertEqualObjects(authRequest.responseType, OIDResponseTypeCode);
XCTAssertEqualObjects(authRequest.redirectURL, [[NSURL alloc] initWithString:@""]);
XCTAssertEqualObjects(authRequestTVAuthorizationEndpoint,
serviceConfiguration.TVAuthorizationEndpoint);
XCTAssertEqualObjects(authRequestDeviceAuthorizationEndpoint,
serviceConfiguration.deviceAuthorizationEndpoint);
}

/*! @brief Tests the @c NSCopying implementation by round-tripping an instance through the copying
* process and checking to make sure the source and destination both contain the
* @c TVAuthorizationEndpoint
* process and checking to make sure the source and destination both contain the
* @c deviceAuthorizationEndpoint
*/
- (void)testCopying {
OIDTVServiceConfiguration *serviceConfiguration = [self testServiceConfiguration];
Expand All @@ -159,16 +159,16 @@ - (void)testCopying {
additionalParameters:nil];

OIDTVAuthorizationRequest *authRequestCopy = [authRequest copy];
NSURL *authRequestCopyTVAuthorizationEndpoint =
((OIDTVServiceConfiguration *)authRequestCopy.configuration).TVAuthorizationEndpoint;
NSURL *authRequestCopyDeviceAuthorizationEndpoint =
((OIDTVServiceConfiguration *)authRequestCopy.configuration).deviceAuthorizationEndpoint;

XCTAssertEqualObjects(authRequestCopyTVAuthorizationEndpoint,
serviceConfiguration.TVAuthorizationEndpoint);
XCTAssertEqualObjects(authRequestCopyDeviceAuthorizationEndpoint,
serviceConfiguration.deviceAuthorizationEndpoint);
}

/*! @brief Tests the @c NSSecureCoding implementation by round-tripping an instance through the
* coding process and checking to make sure the source and destination both contain the
* @c TVAuthorizationEndpoint
* coding process and checking to make sure the source and destination both contain the
* @c deviceAuthorizationEndpoint
*/
- (void)testSecureCoding {
OIDTVServiceConfiguration *serviceConfiguration = [self testServiceConfiguration];
Expand All @@ -183,11 +183,11 @@ - (void)testSecureCoding {
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:authRequest];
OIDTVAuthorizationRequest *authRequestCopy = [NSKeyedUnarchiver unarchiveObjectWithData:data];

NSURL *authRequestCopyTVAuthorizationEndpoint =
((OIDTVServiceConfiguration *)authRequestCopy.configuration).TVAuthorizationEndpoint;
NSURL *authRequestCopyDeviceAuthorizationEndpoint =
((OIDTVServiceConfiguration *)authRequestCopy.configuration).deviceAuthorizationEndpoint;

XCTAssertEqualObjects(authRequestCopyTVAuthorizationEndpoint,
serviceConfiguration.TVAuthorizationEndpoint);
XCTAssertEqualObjects(authRequestCopyDeviceAuthorizationEndpoint,
serviceConfiguration.deviceAuthorizationEndpoint);
}

/*! @brief Tests the @c URLRequest method on a request with no scopes or additional parameters
Expand All @@ -207,7 +207,7 @@ - (void)testURLRequestBasicClientAuth {
XCTAssertEqualObjects(URLRequest.HTTPMethod, kHTTPPost);
XCTAssertEqualObjects([URLRequest valueForHTTPHeaderField:kHTTPContentTypeHeaderKey],
kHTTPContentTypeHeaderValue);
XCTAssertEqualObjects(URLRequest.URL, serviceConfiguration.TVAuthorizationEndpoint);
XCTAssertEqualObjects(URLRequest.URL, serviceConfiguration.deviceAuthorizationEndpoint);

NSDictionary<NSString *, NSString *> *bodyParameters =
[self bodyParametersFromURLRequest:URLRequest];
Expand Down Expand Up @@ -238,7 +238,7 @@ - (void)testURLRequestScopes {
XCTAssertEqualObjects([URLRequest HTTPMethod], kHTTPPost);
XCTAssertEqualObjects([URLRequest valueForHTTPHeaderField:kHTTPContentTypeHeaderKey],
kHTTPContentTypeHeaderValue);
XCTAssertEqualObjects(URLRequest.URL, serviceConfiguration.TVAuthorizationEndpoint);
XCTAssertEqualObjects(URLRequest.URL, serviceConfiguration.deviceAuthorizationEndpoint);

NSDictionary<NSString *, NSString *> *bodyParameters =
[self bodyParametersFromURLRequest:URLRequest];
Expand Down Expand Up @@ -269,7 +269,7 @@ - (void)testURLRequestAdditionalParams {
XCTAssertEqualObjects([URLRequest HTTPMethod], kHTTPPost);
XCTAssertEqualObjects([URLRequest valueForHTTPHeaderField:kHTTPContentTypeHeaderKey],
kHTTPContentTypeHeaderValue);
XCTAssertEqualObjects(URLRequest.URL, serviceConfiguration.TVAuthorizationEndpoint);
XCTAssertEqualObjects(URLRequest.URL, serviceConfiguration.deviceAuthorizationEndpoint);

NSDictionary<NSString *, NSString *> *bodyParameters =
[self bodyParametersFromURLRequest:URLRequest];
Expand Down
8 changes: 4 additions & 4 deletions UnitTests/AppAuthTV/OIDTVAuthorizationResponseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#import "Source/AppAuthTV/OIDTVTokenRequest.h"
#endif

/*! @brief Test value for the @c TVAuthorizationEndpoint property.
/*! @brief Test value for the @c deviceAuthorizationEndpoint property.
*/
static NSString *const kTestTVAuthorizationEndpoint = @"https://www.example.com/device/code";
static NSString *const kTestDeviceAuthorizationEndpoint = @"https://www.example.com/device/code";

/*! @brief Test value for the @c tokenEndpoint property.
*/
Expand Down Expand Up @@ -110,10 +110,10 @@ @implementation OIDTVAuthorizationResponseTests

- (OIDTVServiceConfiguration *)testServiceConfiguration {
NSURL *tokenEndpoint = [NSURL URLWithString:kTestTokenEndpoint];
NSURL *TVAuthorizationEndpoint = [NSURL URLWithString:kTestTVAuthorizationEndpoint];
NSURL *deviceAuthorizationEndpoint = [NSURL URLWithString:kTestDeviceAuthorizationEndpoint];

OIDTVServiceConfiguration *configuration =
[[OIDTVServiceConfiguration alloc] initWithTVAuthorizationEndpoint:TVAuthorizationEndpoint
[[OIDTVServiceConfiguration alloc] initWithDeviceAuthorizationEndpoint:deviceAuthorizationEndpoint
tokenEndpoint:tokenEndpoint];
return configuration;
}
Expand Down
22 changes: 11 additions & 11 deletions UnitTests/AppAuthTV/OIDTVTokenRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu"

/*! @brief Test value for the @c TVAuthorizationEndpoint property.
/*! @brief Test value for the @c deviceAuthorizationEndpoint property.
*/
static NSString *const kTestTVAuthorizationEndpoint =
static NSString *const kTestDeviceAuthorizationEndpoint =
@"https://www.example.com/device/code";

/*! @brief Test value for the @c tokenEndpoint property.
Expand Down Expand Up @@ -106,11 +106,11 @@ @implementation OIDTVTokenRequestTests

- (OIDTVServiceConfiguration *)testServiceConfiguration {
NSURL *tokenEndpoint = [NSURL URLWithString:kTestTokenEndpoint];
NSURL *TVAuthorizationEndpoint = [NSURL URLWithString:kTestTVAuthorizationEndpoint];
NSURL *deviceAuthorizationEndpoint = [NSURL URLWithString:kTestDeviceAuthorizationEndpoint];

OIDTVServiceConfiguration *configuration =
[[OIDTVServiceConfiguration alloc] initWithTVAuthorizationEndpoint:TVAuthorizationEndpoint
tokenEndpoint:tokenEndpoint];
OIDTVServiceConfiguration *configuration = [[OIDTVServiceConfiguration alloc]
initWithDeviceAuthorizationEndpoint:deviceAuthorizationEndpoint
tokenEndpoint:tokenEndpoint];
return configuration;
}

Expand All @@ -128,11 +128,11 @@ - (OIDTVTokenRequest *)testTokenRequest {
*/
- (void)testInitializer {
OIDTVTokenRequest *request = [self testTokenRequest];
NSURL *requestTVAuthorizationEndpoint =
((OIDTVServiceConfiguration *)request.configuration).TVAuthorizationEndpoint;
XCTAssertEqualObjects(requestTVAuthorizationEndpoint,
[self testServiceConfiguration].TVAuthorizationEndpoint);
NSURL *requestDeviceAuthorizationEndpoint =
((OIDTVServiceConfiguration *)request.configuration).deviceAuthorizationEndpoint;

XCTAssertEqualObjects(requestDeviceAuthorizationEndpoint,
[self testServiceConfiguration].deviceAuthorizationEndpoint);
XCTAssertEqualObjects(request.deviceCode, kDeviceCodeValue);
XCTAssertEqualObjects(request.grantType, kOIDTVDeviceTokenGrantType);
XCTAssertEqualObjects(request.clientID, kTestClientID);
Expand Down

0 comments on commit 88136c3

Please sign in to comment.