Skip to content

Commit e6589a9

Browse files
committed
Fixing an actual SDK bug: scopes from dynamic config were NOT being used when constructing the approval URL
1 parent 086e197 commit e6589a9

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/OAuth/SFOAuthCoordinator+Internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ NS_ASSUME_NONNULL_BEGIN
8181
* Returns the scope query parameter string for OAuth requests.
8282
* @return A properly formatted scope parameter string, or empty string if no scopes provided.
8383
*/
84-
- (NSString *)scopeQueryParamString;
84+
- (NSString *)scopeQueryParamString:(NSArray<NSString*>*)scopes;
8585

8686
/**
8787
Migrates the refresh token for a user to a new app configuration.

libs/SalesforceSDKCore/SalesforceSDKCore/Classes/OAuth/SFOAuthCoordinator.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ - (NSString *)approvalURLForEndpoint:(NSString *)authorizeEndpoint
821821
}
822822

823823
// OAuth scopes
824-
NSString *scopeString = [self scopeQueryParamString];
824+
NSString *scopeString = [self scopeQueryParamString:self.credentials.scopes];
825825
if (scopeString.length > 0) {
826826
[approvalUrlString appendString:scopeString];
827827
}
@@ -842,9 +842,9 @@ -(void) clearFrontDoorBridgeLoginOverride {
842842
self.frontdoorBridgeLoginOverride = nil;
843843
}
844844

845-
- (NSString *)scopeQueryParamString {
846-
if (self.scopes.count > 0) {
847-
NSString *scopeStr = [SFScopeParser computeScopeParameterWithURLEncodingWithScopes:self.scopes];
845+
- (NSString *)scopeQueryParamString:(NSArray<NSString*>*)scopes {
846+
if (scopes.count > 0) {
847+
NSString *scopeStr = [SFScopeParser computeScopeParameterWithURLEncodingWithScopes:[NSSet setWithArray:scopes]];
848848
return [NSString stringWithFormat:@"&%@=%@", kSFOAuthScope, scopeStr];
849849
} else {
850850
return @"";

libs/SalesforceSDKCore/SalesforceSDKCoreTests/SalesforceOAuthUnitTests.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -464,10 +464,10 @@ - (void)testDefaultTokenEncryption {
464464
- (void)testScopeQueryParamStringEmptyScopes {
465465
// Given
466466
SFOAuthCoordinator *coordinator = [[SFOAuthCoordinator alloc] init];
467-
coordinator.scopes = [NSSet set];
467+
NSArray<NSString*> *scopes = [NSArray array];
468468

469469
// When
470-
NSString *result = [coordinator scopeQueryParamString];
470+
NSString *result = [coordinator scopeQueryParamString:scopes];
471471

472472
// Then
473473
XCTAssertEqualObjects(result, @"", @"Empty scopes should return empty string");
@@ -476,10 +476,10 @@ - (void)testScopeQueryParamStringEmptyScopes {
476476
- (void)testScopeQueryParamStringNilScopes {
477477
// Given
478478
SFOAuthCoordinator *coordinator = [[SFOAuthCoordinator alloc] init];
479-
coordinator.scopes = nil;
479+
NSArray<NSString*> *scopes = nil;
480480

481481
// When
482-
NSString *result = [coordinator scopeQueryParamString];
482+
NSString *result = [coordinator scopeQueryParamString:scopes];
483483

484484
// Then
485485
XCTAssertEqualObjects(result, @"", @"Nil scopes should return empty string");
@@ -488,10 +488,10 @@ - (void)testScopeQueryParamStringNilScopes {
488488
- (void)testScopeQueryParamStringSingleScope {
489489
// Given
490490
SFOAuthCoordinator *coordinator = [[SFOAuthCoordinator alloc] init];
491-
coordinator.scopes = [NSSet setWithObject:@"web"];
491+
NSArray<NSString*> *scopes = @[@"web"];
492492

493493
// When
494-
NSString *result = [coordinator scopeQueryParamString];
494+
NSString *result = [coordinator scopeQueryParamString:scopes];
495495

496496
// Then
497497
// Should include refresh_token and the provided scope, URL encoded
@@ -501,10 +501,10 @@ - (void)testScopeQueryParamStringSingleScope {
501501
- (void)testScopeQueryParamStringMultipleScopes {
502502
// Given
503503
SFOAuthCoordinator *coordinator = [[SFOAuthCoordinator alloc] init];
504-
coordinator.scopes = [NSSet setWithObjects:@"web", @"api", @"id", nil];
504+
NSArray<NSString*> *scopes = @[@"web", @"api", @"id"];
505505

506506
// When
507-
NSString *result = [coordinator scopeQueryParamString];
507+
NSString *result = [coordinator scopeQueryParamString:scopes];
508508

509509
// Then
510510
// Should include refresh_token and all provided scopes, sorted and URL encoded
@@ -514,10 +514,10 @@ - (void)testScopeQueryParamStringMultipleScopes {
514514
- (void)testScopeQueryParamStringWithRefreshTokenAlreadyPresent {
515515
// Given
516516
SFOAuthCoordinator *coordinator = [[SFOAuthCoordinator alloc] init];
517-
coordinator.scopes = [NSSet setWithObjects:@"web", @"api", @"refresh_token", nil];
518-
517+
NSArray<NSString*> *scopes = @[@"web", @"api", @"refresh_token"];
518+
519519
// When
520-
NSString *result = [coordinator scopeQueryParamString];
520+
NSString *result = [coordinator scopeQueryParamString:scopes];
521521

522522
// Then
523523
// Should still work correctly even if refresh_token is already present

0 commit comments

Comments
 (0)