Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit ceafa38

Browse files
author
Brian Retterer
committed
Merge branch 'release/1.13.0'
Conflicts: CHANGES.md tests/Resource/AccountTest.php
2 parents d3371d1 + e08575d commit ceafa38

File tree

161 files changed

+2349
-191
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

161 files changed

+2349
-191
lines changed

.travis.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
language: php
2-
32
php:
43
- 5.6
54
- 5.5
65
- 5.4
7-
86
sudo: false
9-
107
services:
11-
- redis-server
12-
- memcached
13-
8+
- redis-server
9+
- memcached
1410
before_script:
1511
- composer self-update
1612
- travis_retry composer install --prefer-dist --no-interaction
1713
- mkdir -p ~/.phpenv/versions/$(phpenv version-name)/etc
1814
- echo "extension = memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
1915
- echo "extension = redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
20-
2116
script:
22-
- travis_retry vendor/bin/phpunit --coverage-clover build/logs/clover.xml
23-
17+
- travis_retry vendor/bin/phpunit --coverage-clover build/logs/clover.xml
2418
after_success:
25-
- bash <(curl -s https://codecov.io/bash)
26-
19+
- bash <(curl -s https://codecov.io/bash)
20+
notifications:
21+
hipchat:
22+
rooms:
23+
secure: DN61iUJL9kBtBfPqdHZk67IvadLdSR8+X2dV79qxx/OAFjhu+rW/K0PQp2VEgpUwHwROJxPhxiwXO8OLaA8v7rD7yp9diYwG8gjrmbOcLOphPhMuRlxSfDddWS7Eo7C177KfB2/WEbFhXhav4rDeso8xRUvGJwxqe1TYLQ7cwZo=
24+
template:
25+
- '%{repository}#%{build_number} (%{branch} - %{commit} : %{author}): %{message} (<a href="%{build_url}">Details</a>/<a href="%{compare_url}">Change view</a>)'
26+
format: html

CHANGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
stormpath-sdk-php Changelog
22
===========================
33

4+
Version 1.13.0
5+
--------------
6+
7+
Released on January 26, 2015
8+
9+
- Added SAML to the SDK!
10+
- Add ability to use the password reset token from the normal workflow inside of the ID Site
11+
- Updated Copyright Dates in all files.
12+
- Updated travis notification to send message to HipChat channel
13+
14+
415
Version 1.12.2
516
--------------
617

README.md

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ On your project root, install Composer
2222
Configure the **stormpath/sdk** dependency in your 'composer.json' file:
2323

2424
"require": {
25-
"stormpath/sdk": "1.12.*"
25+
"stormpath/sdk": "1.13.*"
2626
}
2727

2828
On your project root, install the the SDK with its dependencies:
@@ -639,6 +639,21 @@ $forgotLink = $application->createIdSiteUrl(['path'=>'/#/forgot','callbackUri'=>
639639
header('Location:'.$forgotLink); //or any other form of redirect to the $loginLink you want to use.
640640
```
641641

642+
##### Using SP_Token for password reset from workflow in ID Site
643+
644+
We allow you to use the Workflow for password reset outside of the ID Site system, but enable you to use the password
645+
reset screens of the ID Site to do the password reset. To allow for this, you need to pass in the `sp_token` parameter
646+
that was provided in the email of the password reset.
647+
```php
648+
$application = \Stormpath\Resource\Application::get('{APPLICATION_ID}');
649+
$location = $application->createIdSiteUrl([
650+
'path'=>'/#/reset',
651+
'sp_token'=>'{{SP_TOKEN}}',
652+
'callbackUri'=>'{{CALLBACK_URI}}'
653+
]);
654+
header('Location:'.$forgotLink); //or any other form of redirect to the $loginLink you want to use.
655+
```
656+
642657
Again, with all these methods, You will want your application to link to an internal page where the JWT is created at
643658
that time. Without doing this, a user will only have 60 seconds to click on the link before the JWT expires.
644659

@@ -918,6 +933,167 @@ $authenticationRequest = new UsernamePasswordRequest('usernameOrEmail', 'passwor
918933
$result = $application->authenticateAccount($authenticationRequest);
919934
```
920935

936+
937+
### Authenticating Against a SAML Directory
938+
939+
940+
SAML is an XML-based standard for exchanging authentication and authorization data between security domains. Stormpath enables you to allow customers to log-in by authenticating with an external SAML Identity Provider.
941+
942+
#### Stormpath as a Service Provider
943+
944+
The specific use case that Stormpath supports is user-initiated single sign-on. In this scenario, a user requests a protected resource (e.g. your application). Your application, with the help of Stormpath, then confirms the users identity in order to determine whether they are able to access the resource. In SAML terminology, the user is the **User Agent**, your application (along with Stormpath) is the **Service Provider**, and the third-party SAML authentication site is the **Identity Provider** or **IdP**.
945+
946+
The broad strokes of the process are as follows:
947+
948+
- User Agent requests access from Service Provider
949+
- Service Provider responds with redirect to Identity Provider
950+
- Identity Provider authenticates the user
951+
- Identity provider redirects user back to Service Provider along with SAML assertions.
952+
- Service Provider receives SAML assertions and either creates or retrieves Account information
953+
954+
Just like with Mirror and Social Directories, the user information that is returned from the IdP is used by Stormpath to either identify an existing Account resource, or create a new one. In the case of new Account creation, Stormpath will map the information in the response onto its own resources. In this section we will walk you through the process of configuring your SAML Directory, as well as giving you an overview of how the SAML Authentication process works.
955+
956+
957+
#### Configuring Stormpath as a Service Provider
958+
959+
Configuration is stored in the Directory's `Provider resource `. Both of these resources must also be linked with an `AccountStoreMapping`. Here we will explain to you the steps that are required to configure Stormpath as a SAML Service Provider.
960+
961+
##### Step 1: Gather IDP Data
962+
963+
You will need the following information from your IdP:
964+
965+
- **SSO Login URL** - The URL at the IdP to which SAML authentication requests should be sent. This is often called an "SSO URL", "Login URL" or "Sign-in URL".
966+
- **SSO Logout URL** - The URL at the IdP to which SAML logout requests should be sent. This is often called a "Logout URL", "Global Logout URL" or "Single Logout URL".
967+
- **Signing Cert** - The IdP will digitally sign auth assertions and Stormpath will need to validate the signature. This will usually be in .pem or .crt format, but Stormpath requires the text value.
968+
- **Signing Algorithm** - You will need the name of the signing algorithm that your IdP uses. It will be either "RSA-SHA256" or "RSA-SHA1".
969+
970+
##### Step 2: Configure Your SAML Directory
971+
972+
Input the data you gathered in Step 1 above into your Directory's Provider resource, and then pass that along as part of the Directory creation HTTP POST:
973+
974+
```
975+
$samlProvider = \Stormpath\Resource\SamlProvider::instantiate([
976+
'ssoLoginUrl' => 'http://google.com/login',
977+
'ssoLogoutUrl' => 'http://google.com/logout',
978+
'encodedX509SigningCert' => $this->getDummyCertForSaml(),
979+
'requestSignatureAlgorithm' => 'RSA-SHA1'
980+
]);
981+
982+
$directory = \Stormpath\Resource\Directory::create([
983+
'name' => makeUniqueName('DirectoryTest samlProvider'),
984+
'provider' => $samlProvider
985+
]);
986+
```
987+
988+
989+
990+
> Notice that new lines in the certificate are separated with a ``\n`` character.
991+
992+
993+
##### Retrieve Your Service Provider Metadata
994+
995+
Next you will have to configure your Stormpath-powered application as a Service Provider in your Identity Provider. This means that you will need to retrieve the correct metadata from Stormpath.
996+
997+
In order to retrieve the required values, start by sending a GET to the Directory's Provider:
998+
999+
```
1000+
$provider = Stormpath\Resource\SamlProvider::get(self::$directory->provider->href);
1001+
$providerMetaData = $provider->serviceProviderMetadata
1002+
```
1003+
1004+
From this metadata, you will need two values:
1005+
1006+
- **Assertion Consumer Service URL**: This is the location the IdP will send its response to.
1007+
- **X509 Signing Certificate**: The certificate that is used to sign the requests sent to the IdP. If you retrieve XML, the certificate will be embedded. If you retrieve JSON, you'll have to follow a further ``/x509certificates`` link to retrieve it.
1008+
1009+
You will also need two other values, which will always be the same:
1010+
1011+
- **SAML Request Binding:** Set to ``HTTP-Redirect``.
1012+
- **SAML Response Binding:** Set to ``HTTP-Post``.
1013+
1014+
##### Step 4: Configure Your Service Provider in Your Identity Provider
1015+
1016+
Log-in to your Identity Provider (Salesforce, OneLogin, etc) and enter the information you retrieved in the previous step into the relevant application configuration fields. The specific steps to follow here will depend entirely on what Identity Provider you use, and for more information you should consult your Identity Provider's SAML documentation.
1017+
1018+
##### Step 5: Configure Your Application
1019+
1020+
The Stormpath `Application` Resource has two parts that are relevant to SAML:
1021+
1022+
- an ``authorizedCallbackUri`` Array that defines the authorized URIs that the IdP can return your user to. These should be URIs that you host yourself.
1023+
- an embedded ``samlPolicy`` object that contains information about the SAML flow configuration and endpoints.
1024+
1025+
```
1026+
$application->setAuthorizedCallbackUris([
1027+
'http://myapplication.com/whatever/callback',
1028+
'http://myapplication.com/whatever/callback2'
1029+
]);
1030+
1031+
$application->save();
1032+
1033+
```
1034+
1035+
##### Step 6: Add the SAML Directory as an Account Store
1036+
1037+
Now you last thing you have to do is map the new Directory to your Application with an Account Store Mapping.
1038+
1039+
1040+
##### Step 7: Configure SAML Assertion Mapping
1041+
1042+
The Identity Provider's SAML response contains assertions about the user's identity, which Stormpath can use to create and populate a new Account resource.
1043+
1044+
``` xml
1045+
1046+
<saml:AttributeStatement>
1047+
<saml:Attribute Name="uid" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
1048+
<saml:AttributeValue xsi:type="xs:string">test</saml:AttributeValue>
1049+
</saml:Attribute>
1050+
<saml:Attribute Name="mail" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
1051+
<saml:AttributeValue xsi:type="xs:string">jane@example.com</saml:AttributeValue>
1052+
</saml:Attribute>
1053+
<saml:Attribute Name="location" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic">
1054+
<saml:AttributeValue xsi:type="xs:string">Tampa, FL</saml:AttributeValue>
1055+
</saml:Attribute>
1056+
</saml:AttributeStatement>
1057+
1058+
The Attribute Assertions (`<saml:AttributeStatement>`) are brought into Stormpath and become Account and customData attributes.
1059+
1060+
SAML Assertion mapping is defined in an **attributeStatementMappingRules** object found inside the Directory's Provider object, or directly: `/v1/attributeStatementMappingRules/$RULES_ID`.
1061+
1062+
##### Mapping Rules
1063+
1064+
The rules have three different components:
1065+
1066+
- **name**: The SAML Attribute name
1067+
- **nameFormat**: The name format for this SAML Attribute, expressed as a Uniform Resource Name (URN).
1068+
- **accountAttributes**: This is an array of Stormpath Account or customData (`customData.$KEY_NAME`) attributes that will map to this SAML Attribute.
1069+
1070+
1071+
1072+
In order to create the mapping rules, we simply send the following:
1073+
1074+
```
1075+
$provider = \Stormpath\Resource\SamlProvider::get($directory->provider->href);
1076+
1077+
$ruleBuilder = new \Stormpath\Saml\AttributeStatementMappingRuleBuilder();
1078+
$rule = $ruleBuilder->setName('test1')
1079+
->setAccountAttributes(['customData.test1'])
1080+
->build();
1081+
1082+
$rule2 = $ruleBuilder->setName('test2')
1083+
->setAccountAttributes(['customData.test2'])
1084+
->build();
1085+
1086+
1087+
$rulesBuilder = new \Stormpath\Saml\AttributeStatementMappingRulesBuilder();
1088+
$rulesBuilder->setAttributeStatementMappingRules([$rule, $rule2]);
1089+
$rules = $rulesBuilder->build();
1090+
1091+
$provider->setAttributeStatementMappingRules($rules);
1092+
1093+
$provider->save();
1094+
```
1095+
1096+
9211097
### Verify an Account's email address
9221098
9231099
This workflow allows you to send a welcome email to a newly registered account and optionally verify that they own the

src/ApiKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Stormpath;
44

55
/*
6-
* Copyright 2013 Stormpath, Inc.
6+
* Copyright 2016 Stormpath, Inc.
77
*
88
* Licensed under the Apache License, Version 2.0 (the "License");
99
* you may not use this file except in compliance with the License.

src/Authc/Api/ApiAuthenticationResult.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
* Copyright 2016 Stormpath, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
217

318
namespace Stormpath\Authc\Api;
419

src/Authc/Api/ApiKeyEncryptionOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Stormpath\Authc\Api;
44

55
/*
6-
* Copyright 2013 Stormpath, Inc.
6+
* Copyright 2016 Stormpath, Inc.
77
*
88
* Licensed under the Apache License, Version 2.0 (the "License");
99
* you may not use this file except in compliance with the License.

src/Authc/Api/ApiKeyEncryptionUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Stormpath\Authc\Api;
44

55
/*
6-
* Copyright 2013 Stormpath, Inc.
6+
* Copyright 2016 Stormpath, Inc.
77
*
88
* Licensed under the Apache License, Version 2.0 (the "License");
99
* you may not use this file except in compliance with the License.

src/Authc/Api/ApiRequestAuthenticator.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
* Copyright 2016 Stormpath, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
217

318
namespace Stormpath\Authc\Api;
419

src/Authc/Api/AuthenticatorResult.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
* Copyright 2016 Stormpath, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
217

318
namespace Stormpath\Authc\Api;
419

src/Authc/Api/BasicAuthenticationResult.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
<?php
2+
/*
3+
* Copyright 2016 Stormpath, Inc.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
217

318
namespace Stormpath\Authc\Api;
419

0 commit comments

Comments
 (0)