Skip to content

Commit 6ff2f9c

Browse files
author
Jon Hjelle
committed
Allow a username different than the user part of a JID to be used for all SASL-based authentication methods.
1 parent bebc2d4 commit 6ff2f9c

File tree

5 files changed

+35
-14
lines changed

5 files changed

+35
-14
lines changed

Authentication/Digest-MD5/XMPPDigestMD5Authentication.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ + (NSString *)mechanismName
7070
@synthesize password;
7171

7272
- (id)initWithStream:(XMPPStream *)stream password:(NSString *)inPassword
73+
{
74+
return [self initWithStream:stream username:nil password:inPassword];
75+
}
76+
77+
- (id)initWithStream:(XMPPStream *)stream username:(NSString *)inUsername password:(NSString *)inPassword
7378
{
7479
if ((self = [super init]))
7580
{
7681
xmppStream = stream;
82+
username = inUsername;
7783
password = inPassword;
7884
}
7985
return self;
@@ -140,7 +146,10 @@ - (XMPPHandleAuthResponse)handleAuth1:(NSXMLElement *)authResponse
140146
if (cnonce == nil)
141147
cnonce = [XMPPStream generateUUID];
142148

143-
username = [myJID user];
149+
if (username == nil)
150+
{
151+
username = [myJID user];
152+
}
144153

145154
// Create and send challenge response element
146155

Authentication/Plain/XMPPPlainAuthentication.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@
99
//
1010
// See XMPPSASLAuthentication.h for more information.
1111

12-
/**
13-
* Use this init method if the username used for authentication does not match the user part of the JID.
14-
* If inUsername is nil, the user part of the JID will be used. The standard init method will use the
15-
* user part of the JID as the username.
16-
**/
17-
- (id)initWithStream:(XMPPStream *)stream username:(NSString *)inUsername password:(NSString *)inPassword;
18-
1912
@end
2013

2114
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Authentication/Plain/XMPPPlainAuthentication.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ + (NSString *)mechanismName
3434
return @"PLAIN";
3535
}
3636

37+
- (id)initWithStream:(XMPPStream *)stream password:(NSString *)inPassword
38+
{
39+
return [self initWithStream:stream username:nil password:inPassword];
40+
}
41+
3742
- (id)initWithStream:(XMPPStream *)stream username:(NSString *)inUsername password:(NSString *)inPassword
3843
{
3944
if ((self = [super init]))
@@ -45,11 +50,6 @@ - (id)initWithStream:(XMPPStream *)stream username:(NSString *)inUsername passwo
4550
return self;
4651
}
4752

48-
- (id)initWithStream:(XMPPStream *)stream password:(NSString *)inPassword
49-
{
50-
return [self initWithStream:stream username:nil password:inPassword];
51-
}
52-
5353
- (BOOL)start:(NSError **)errPtr
5454
{
5555
XMPPLogTrace();

Authentication/SCRAM-SHA-1/XMPPSCRAMSHA1Authentication.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,22 @@ + (NSString *)mechanismName
6464
}
6565

6666
- (id)initWithStream:(XMPPStream *)stream password:(NSString *)password
67+
{
68+
return [self initWithStream:stream username:nil password:inPassword];
69+
}
70+
71+
- (id)initWithStream:(XMPPStream *)stream username:(NSString *)inUsername password:(NSString *)inPassword
6772
{
6873
if ((self = [super init])) {
6974
xmppStream = stream;
70-
_username = [XMPPStringPrep prepNode:[xmppStream.myJID user]];
75+
if (inUsername)
76+
{
77+
_username = inUsername;
78+
}
79+
else
80+
{
81+
_username = [XMPPStringPrep prepNode:[xmppStream.myJID user]];
82+
}
7183
_password = [XMPPStringPrep prepPassword:password];
7284
_hashAlgorithm = kCCHmacAlgSHA1;
7385
}

Authentication/XMPPSASLAuthentication.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ typedef NS_ENUM(NSInteger, XMPPHandleAuthResponse) {
5858
**/
5959
- (id)initWithStream:(XMPPStream *)stream password:(NSString *)password;
6060

61+
/**
62+
* Use this init method if the username used for authentication does not match the user part of the JID.
63+
* If username is nil, the user part of the JID will be used.
64+
* The standard init method uses this init method, passing nil for the username.
65+
**/
66+
- (id)initWithStream:(XMPPStream *)stream username:(NSString *)username password:(NSString *)password;
67+
6168
/**
6269
* Attempts to start the authentication process.
6370
* The auth mechanism should send whatever stanzas are needed to begin the authentication process.

0 commit comments

Comments
 (0)