Skip to content

Commit

Permalink
Merge pull request #240 from auth0/fix-oauth-access-token-connection
Browse files Browse the repository at this point in the history
Avoid overriding connection name for social login
  • Loading branch information
hzalaz committed Mar 22, 2016
2 parents 759de0e + 99eefa0 commit 4def7b5
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Lock/Core/A0APIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ - (NSURLSessionDataTask *)authenticateWithSocialConnectionName:(NSString *)conne
failure:(A0APIClientError)failure {
NSDictionary *params = @{
kClientIdParamName: self.clientId,
kConnectionParamName: connectionName,
};
A0AuthParameters *defaultParameters = [A0AuthParameters newWithDictionary:params];
if (credentials.extraInfo[A0StrategySocialTokenSecretParameter]) {
Expand All @@ -363,6 +362,7 @@ - (NSURLSessionDataTask *)authenticateWithSocialConnectionName:(NSString *)conne
defaultParameters[A0ParameterMainAccessToken] = defaultParameters.accessToken;
}
defaultParameters.accessToken = credentials.accessToken;
defaultParameters[kConnectionParamName] = connectionName;

NSDictionary *payload = [defaultParameters asAPIPayload];
A0LogVerbose(@"Authenticating with social strategy %@ and payload %@", connectionName, payload);
Expand Down
20 changes: 2 additions & 18 deletions Lock/UI/NIBs/A0SignUpViewController.xib
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9060" systemVersion="15B42" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9051"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="A0SignUpViewController">
Expand All @@ -25,7 +25,6 @@
<subviews>
<button opaque="NO" contentMode="scaleToFill" horizontalCompressionResistancePriority="1000" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="BV3-3N-All" customClass="A0ProgressButton">
<rect key="frame" x="21" y="206" width="238" height="55"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="55" id="1Pb-dt-8u6"/>
</constraints>
Expand All @@ -41,7 +40,6 @@
</button>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Please enter your email and password" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gL1-Ds-LKT">
<rect key="frame" x="26" y="10" width="229" height="16"/>
<animations/>
<constraints>
<constraint firstAttribute="height" constant="16" id="4m8-GP-aJF"/>
</constraints>
Expand All @@ -57,7 +55,6 @@
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Username" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="tIl-xc-rd0">
<rect key="frame" x="44" y="10" width="187" height="30"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="next"/>
<connections>
Expand All @@ -66,11 +63,9 @@
</textField>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Auth0.bundle/person" translatesAutoresizingMaskIntoConstraints="NO" id="B4K-1n-dxc">
<rect key="frame" x="18" y="17" width="16" height="16"/>
<animations/>
<color key="tintColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
</imageView>
</subviews>
<animations/>
<constraints>
<constraint firstItem="B4K-1n-dxc" firstAttribute="leading" secondItem="uPM-Ir-6l4" secondAttribute="leading" constant="18" id="0KR-4t-H1K"/>
<constraint firstItem="B4K-1n-dxc" firstAttribute="centerY" secondItem="tIl-xc-rd0" secondAttribute="centerY" id="5yg-Uy-xzE"/>
Expand All @@ -87,7 +82,6 @@
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="013-KC-liE">
<rect key="frame" x="0.0" y="50" width="238" height="1"/>
<animations/>
<color key="backgroundColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="bfE-5T-9w1"/>
Expand All @@ -98,7 +92,6 @@
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Email" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="mFc-1H-Ngh">
<rect key="frame" x="44" y="10" width="187" height="30"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="next"/>
<connections>
Expand All @@ -107,11 +100,9 @@
</textField>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Auth0.bundle/mail" translatesAutoresizingMaskIntoConstraints="NO" id="59g-GJ-D1f">
<rect key="frame" x="18" y="17" width="16" height="16"/>
<animations/>
<color key="tintColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
</imageView>
</subviews>
<animations/>
<constraints>
<constraint firstItem="59g-GJ-D1f" firstAttribute="leading" secondItem="i5m-Aq-8EN" secondAttribute="leading" constant="18" id="1Bg-bg-Bx6"/>
<constraint firstAttribute="bottom" secondItem="mFc-1H-Ngh" secondAttribute="bottom" constant="10" id="ClP-Zd-KvX"/>
Expand All @@ -128,7 +119,6 @@
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="6sK-qG-ya2">
<rect key="frame" x="0.0" y="101" width="238" height="1"/>
<animations/>
<color key="backgroundColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="OZX-S4-cVz"/>
Expand All @@ -139,7 +129,6 @@
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Password" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Zve-FO-K8J">
<rect key="frame" x="44" y="10" width="187" height="30"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" returnKeyType="go" secureTextEntry="YES"/>
<connections>
Expand All @@ -148,11 +137,9 @@
</textField>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Auth0.bundle/lock" translatesAutoresizingMaskIntoConstraints="NO" id="c9z-aw-6NQ">
<rect key="frame" x="18" y="17" width="16" height="16"/>
<animations/>
<color key="tintColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
</imageView>
</subviews>
<animations/>
<color key="tintColor" red="0.59999999999999998" green="0.59999999999999998" blue="0.59999999999999998" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="Zve-FO-K8J" secondAttribute="trailing" constant="7" id="4XX-bg-THK"/>
Expand All @@ -170,7 +157,6 @@
</connections>
</view>
</subviews>
<animations/>
<constraints>
<constraint firstItem="R6f-hv-Q3N" firstAttribute="leading" secondItem="cls-os-Kzf" secondAttribute="leading" id="0es-10-dXk"/>
<constraint firstItem="R6f-hv-Q3N" firstAttribute="top" secondItem="6sK-qG-ya2" secondAttribute="bottom" id="7au-jC-e2M"/>
Expand All @@ -196,10 +182,8 @@
</view>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="IhG-Wj-xDi">
<rect key="frame" x="0.0" y="261" width="280" height="30"/>
<animations/>
</view>
</subviews>
<animations/>
<constraints>
<constraint firstItem="IhG-Wj-xDi" firstAttribute="leading" secondItem="gRZ-Jn-ZYC" secondAttribute="leading" id="0fG-hx-uLg"/>
<constraint firstItem="IhG-Wj-xDi" firstAttribute="top" secondItem="BV3-3N-All" secondAttribute="bottom" id="7x8-Vn-3E8"/>
Expand Down
55 changes: 55 additions & 0 deletions LockTests/A0APIClientSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,43 @@ class A0APIClientSpec : QuickSpec {
})
}
}

it("should request change password") {
api.allowChangePasswordWithParameters([
"email": EMAIL,
"connection": DB_CONNECTION
])
waitUntil { done in
client.requestChangePasswordForUsername(EMAIL,
parameters: nil,
success: { done() },
failure: { _ in
fail("Should have changed password")
done()
})
}
}

it("should fail to request change password with error") {
api.failForRoute(.ChangePassword,
parameters: [
"email": EMAIL,
"connection": DB_CONNECTION
], message: "failed_change_passsword")
waitUntil { done in
client.requestChangePasswordForUsername(EMAIL,
parameters: nil,
success: {
fail("Should have failed to change password")
done()
},
failure: { error in
expect(error.localizedDescription).to(equal("failed_change_passsword"))
done()
})
}
}

}

describe("login with JWT") {
Expand Down Expand Up @@ -656,6 +693,24 @@ class A0APIClientSpec : QuickSpec {
}
}

it("should not override connection name specified as a method parameter") {
api.allowSocialLoginWithParameters([
"access_token": SOCIAL_TOKEN,
"connection": "facebook",
"scope": "openid offline_access"
])
api.allowTokenInfoForToken(JWT)
let parameters = A0AuthParameters.newDefaultParams()
parameters["connection"] = "invalid connection"
waitUntil { done in
client.authenticateWithSocialConnectionName("facebook",
credentials: credentials,
parameters: parameters,
success: {_, _ in done() },
failure: {_ in fail("Should not have failed")})
}
}

it("should login with access token in parameters") {
let parameters = A0AuthParameters.newDefaultParams()
let accessToken = "AnotherToken"
Expand Down

0 comments on commit 4def7b5

Please sign in to comment.