├── .gitattributes ├── .gitignore ├── LICENSE.txt ├── README.md ├── SECURITY.md ├── WAAD.WebSSO.PHP ├── README-FIRST.txt ├── README.md ├── csharp │ └── code │ │ └── libraries │ │ └── powershell │ │ └── Microsoft.Samples.Waad.PS │ │ ├── GetOrgIdSPN.cs │ │ ├── GetOrgIdSPNResult.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── Settings.StyleCop │ │ └── buildWaadPS.bat └── php │ ├── code │ ├── libraries │ │ ├── federation │ │ │ ├── Claim.php │ │ │ ├── FederatedConfiguration.php │ │ │ ├── FederatedLoginManager.php │ │ │ ├── FederatedPrincipal.php │ │ │ ├── IFederatedAuthenticationObserver.php │ │ │ └── Saml2TokenValidator.php │ │ └── waad-federation │ │ │ ├── ConfigurableFederatedLoginManager.php │ │ │ ├── TrustedIssuer.php │ │ │ └── TrustedIssuersRepository.php │ └── samples │ │ ├── .gitignore │ │ └── phpSample │ │ ├── federation.ini │ │ ├── index.php │ │ ├── login.php │ │ ├── secureResource.php │ │ └── trustedIssuers.xml │ ├── docs │ └── Web SignOn with WAAD - PHP sample.docx │ └── scripts │ ├── CreateServicePrincipal.ps1 │ ├── If your dll is missing-read this.txt │ └── Microsoft.Samples.Waad.PS.lnk ├── storage ├── BlockBlobExample.php └── PageBlobExample.php ├── tasklist-mysql ├── additem.php ├── createtable.php ├── deleteitem.php ├── getitems.php ├── index.php ├── markitemcomplete.php └── taskmodel.php └── tasklist-sqlazure ├── additem.php ├── createtable.php ├── deleteitem.php ├── getitems.php ├── index.php ├── markitemcomplete.php └── taskmodel.php /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | [Dd]ebug/ 46 | [Rr]elease/ 47 | *_i.c 48 | *_p.c 49 | *.ilk 50 | *.meta 51 | *.obj 52 | *.pch 53 | *.pdb 54 | *.pgc 55 | *.pgd 56 | *.rsp 57 | *.sbr 58 | *.tlb 59 | *.tli 60 | *.tlh 61 | *.tmp 62 | *.vspscc 63 | .builds 64 | *.dotCover 65 | 66 | ## TODO: If you have NuGet Package Restore enabled, uncomment this 67 | #packages/ 68 | 69 | # Visual C++ cache files 70 | ipch/ 71 | *.aps 72 | *.ncb 73 | *.opensdf 74 | *.sdf 75 | 76 | # Visual Studio profiler 77 | *.psess 78 | *.vsp 79 | 80 | # ReSharper is a .NET coding add-in 81 | _ReSharper* 82 | 83 | # Installshield output folder 84 | [Ee]xpress 85 | 86 | # DocProject is a documentation generator add-in 87 | DocProject/buildhelp/ 88 | DocProject/Help/*.HxT 89 | DocProject/Help/*.HxC 90 | DocProject/Help/*.hhc 91 | DocProject/Help/*.hhk 92 | DocProject/Help/*.hhp 93 | DocProject/Help/Html2 94 | DocProject/Help/html 95 | 96 | # Click-Once directory 97 | publish 98 | 99 | # Others 100 | [Bb]in 101 | [Oo]bj 102 | sql 103 | TestResults 104 | *.Cache 105 | ClientBin 106 | stylecop.* 107 | ~$* 108 | *.dbmdl 109 | Generated_Code #added for RIA/Silverlight projects 110 | 111 | # Backup & report files from converting an old project file to a newer 112 | # Visual Studio version. Backup files are not needed, because we have git ;-) 113 | _UpgradeReport_Files/ 114 | Backup*/ 115 | UpgradeLog*.XML 116 | 117 | 118 | 119 | ############ 120 | ## Windows 121 | ############ 122 | 123 | # Windows image file caches 124 | Thumbs.db 125 | 126 | # Folder config file 127 | Desktop.ini 128 | 129 | 130 | ############# 131 | ## Python 132 | ############# 133 | 134 | *.py[co] 135 | 136 | # Packages 137 | *.egg 138 | *.egg-info 139 | dist 140 | build 141 | eggs 142 | parts 143 | bin 144 | var 145 | sdist 146 | develop-eggs 147 | .installed.cfg 148 | 149 | # Installer logs 150 | pip-log.txt 151 | 152 | # Unit test / coverage reports 153 | .coverage 154 | .tox 155 | 156 | #Translations 157 | *.mo 158 | 159 | #Mr Developer 160 | .mr.developer.cfg 161 | 162 | # Mac crap 163 | .DS_Store 164 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | azure-sdk-for-php-samples 2 | ========================= 3 | 4 | PHP Sample for articles on windowsazure.com -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/opensource/security/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/opensource/security/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/opensource/security/pgpkey). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://aka.ms/opensource/security/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/opensource/security/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/opensource/security/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/README-FIRST.txt: -------------------------------------------------------------------------------- 1 |  2 | PRE-REQUISITES BEFORE USING THIS SAMPLE 3 | 4 | ************************************************* 5 | 6 | Step 1: Create the Microsoft.Samples.Waad.PS.dll 7 | 8 | ************************************************* 9 | 10 | In order to use the PowerShell cmdlets provided under the %ROOT%/php/scripts/ directory, you will need to build the DLL that provides the WAAD functionality. 11 | 12 | We have included the source for building this DLL in this code for your convenience. It is located at: 13 | 14 | %ROOT%/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/ 15 | 16 | You have two options to build this DLL: 17 | 18 | 1. Build using VS 2010 Tools Command Line and included batch file 19 | 20 | You can build this DLL easily by running: 21 | 22 | %ROOT%/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/buildWaadPS.bat 23 | 24 | This will build the DLL and copy the DLL to the correct location under %ROOT%/php/scripts/ 25 | 26 | 2. Load the .csproj file and build under Visual Studio 2010 or higher 27 | 28 | This is located under %ROOT%/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS. You will need to ensure that the Microsoft.Samples.Waad.PS.dll file is moved to the correct location under %ROOT%/csharp/scripts/ 29 | 30 | 31 | The rest of the setup instructions and walk-through are located at: 32 | 33 | http://www.windowsazure.com/en-us/develop/php/how-to-guides/web-sso/ 34 | 35 | 36 | ******************************************************************** 37 | 38 | STEP 2: Download the simpleSAMLphp library 39 | 40 | ******************************************************************** 41 | 42 | SimpleSAMLphp is an award-winning application written in native PHP that deals with authentication. The project is led by UNINETT, has a large user base, a helpful user community and a large set of external contributors. 43 | 44 | SimpleSAMLphp is having a main focus on providing support for: 45 | •SAML 2.0 as a Service Provider. 46 | •SAML 2.0 as a Identity Provider. 47 | 48 | But also supports some other identity protocols, such as Shibboleth 1.3, A-Select, CAS, OpenID, WS-Federation and OAuth. 49 | 50 | You can download this by going to: http://simplesamlphp.org/ 51 | 52 | and including the base install underneath the root directory such as: 53 | 54 | %ROOT/simplesamlphp 55 | 56 | 57 | 58 | Enjoy! 59 | 60 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/README.md: -------------------------------------------------------------------------------- 1 | azure-sdk-for-php-samples 2 | ========================= 3 | 4 | PHP Sample for articles on windowsazure.com -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/GetOrgIdSPN.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Samples.Waad.PS 2 | { 3 | using System; 4 | using System.Management.Automation; 5 | using System.Xml; 6 | 7 | [Cmdlet(VerbsCommon.Get, "OrgIdConfig")] 8 | public class GetOrgIdSpn : PSCmdlet 9 | { 10 | private const string FederationMetadata = "https://accounts.accesscontrol.windows.net/FederationMetadata/2007-06/FederationMetadata.xml?realm={0}"; 11 | private const string EntityDescriptor = "EntityDescriptor"; 12 | private const string EntityId = "entityID"; 13 | 14 | [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "default", HelpMessage = "The Application Principal Identifier returned when registering a new principal.")] 15 | [ValidateNotNullOrEmpty] 16 | public string AppPrincipalId { get; set; } 17 | 18 | [Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "default", HelpMessage = "The Application Domain used when registering a new principal.")] 19 | [ValidateNotNullOrEmpty] 20 | public string ApplicationDomain { get; set; } 21 | 22 | protected override void ProcessRecord() 23 | { 24 | try 25 | { 26 | base.ProcessRecord(); 27 | 28 | var result = this.GetSpn(); 29 | 30 | Console.Write("\nAdd the following issuer entry to the XML file"); 31 | Console.Write("\n=============================================="); 32 | Console.Write('\n' + result.ToString() + "\n\n"); 33 | } 34 | catch (Exception ex) 35 | { 36 | WriteError(new ErrorRecord(ex, string.Empty, ErrorCategory.CloseError, null)); 37 | } 38 | } 39 | 40 | private GetOrgIdSpnResult GetSpn() 41 | { 42 | string entityDescriptor = string.Empty; 43 | Guid idpIdentifier = Guid.Empty; 44 | 45 | using (var reader = new XmlTextReader(string.Format(FederationMetadata, this.ApplicationDomain))) 46 | { 47 | var xml = new XmlDocument(); 48 | xml.Load(reader); 49 | var descriptor = xml.GetElementsByTagName(EntityDescriptor); 50 | 51 | if ((descriptor != null) && (descriptor.Count > 0)) 52 | { 53 | entityDescriptor = descriptor[0].Attributes[EntityId].Value; 54 | idpIdentifier = new Guid(entityDescriptor.Split('@')[1]); 55 | } 56 | 57 | return new GetOrgIdSpnResult(new Guid(this.AppPrincipalId), this.ApplicationDomain, idpIdentifier); 58 | } 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/GetOrgIdSPNResult.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Samples.Waad.PS 2 | { 3 | using System; 4 | using System.Globalization; 5 | 6 | public class GetOrgIdSpnResult 7 | { 8 | private const string Display = ""; 9 | 10 | public GetOrgIdSpnResult(Guid appId, string appDomain, Guid idpId) 11 | { 12 | this.ApplicationId = appId; 13 | this.ApplicationDomain = appDomain; 14 | this.Spn = string.Format("spn:{0}", appId); 15 | } 16 | 17 | public Guid ApplicationId { get; internal set; } 18 | 19 | public string ApplicationDomain { get; internal set; } 20 | 21 | public string Spn { get; internal set; } 22 | 23 | public override string ToString() 24 | { 25 | return string.Format(CultureInfo.InvariantCulture, Display, this.ApplicationDomain, this.Spn); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Microsoft.Samples.Waad.PS")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Microsoft.Samples.Waad.PS")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("08dbf7c3-adc5-4c47-9124-5321a7b7c999")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/Settings.StyleCop: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | False 8 | 9 | 10 | 11 | 12 | False 13 | 14 | 15 | 16 | 17 | False 18 | 19 | 20 | 21 | 22 | False 23 | 24 | 25 | 26 | 27 | False 28 | 29 | 30 | 31 | 32 | False 33 | 34 | 35 | 36 | 37 | False 38 | 39 | 40 | 41 | 42 | False 43 | 44 | 45 | 46 | 47 | False 48 | 49 | 50 | 51 | 52 | False 53 | 54 | 55 | 56 | 57 | False 58 | 59 | 60 | 61 | 62 | False 63 | 64 | 65 | 66 | 67 | False 68 | 69 | 70 | 71 | 72 | False 73 | 74 | 75 | 76 | 77 | False 78 | 79 | 80 | 81 | 82 | False 83 | 84 | 85 | 86 | 87 | False 88 | 89 | 90 | 91 | 92 | False 93 | 94 | 95 | 96 | 97 | False 98 | 99 | 100 | 101 | 102 | False 103 | 104 | 105 | 106 | 107 | False 108 | 109 | 110 | 111 | 112 | False 113 | 114 | 115 | 116 | 117 | False 118 | 119 | 120 | 121 | 122 | False 123 | 124 | 125 | 126 | 127 | False 128 | 129 | 130 | 131 | 132 | False 133 | 134 | 135 | 136 | 137 | False 138 | 139 | 140 | 141 | 142 | False 143 | 144 | 145 | 146 | 147 | False 148 | 149 | 150 | 151 | 152 | False 153 | 154 | 155 | 156 | 157 | False 158 | 159 | 160 | 161 | 162 | False 163 | 164 | 165 | 166 | 167 | False 168 | 169 | 170 | 171 | 172 | False 173 | 174 | 175 | 176 | 177 | False 178 | 179 | 180 | 181 | 182 | False 183 | 184 | 185 | 186 | 187 | False 188 | 189 | 190 | 191 | 192 | False 193 | 194 | 195 | 196 | 197 | False 198 | 199 | 200 | 201 | 202 | False 203 | 204 | 205 | 206 | 207 | False 208 | 209 | 210 | 211 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/buildWaadPS.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | MSBuild Microsoft.Samples.Waad.PS.csproj /property:Configuration=Debug -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/federation/Claim.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | claimType = $type; 30 | $this->claimValue = $value; 31 | } 32 | 33 | public function getClaimValues() { 34 | return explode(',', $this->claimValue); 35 | } 36 | 37 | public function toString() { 38 | return 'Claim [claimType=' . $this->claimType . ', claimValue=' . $this->claimValue . ']'; 39 | } 40 | } 41 | ?> 42 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/federation/FederatedConfiguration.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | properties = parse_ini_file('federation.ini'); 37 | } 38 | 39 | public function getStsUrl() { 40 | return $this->properties['federation.trustedissuers.issuer']; 41 | } 42 | 43 | public function getStsFriendlyName() { 44 | return $this->properties['federation.trustedissuers.friendlyname']; 45 | } 46 | 47 | public function getThumbprint() { 48 | return $this->properties['federation.trustedissuers.thumbprint']; 49 | } 50 | 51 | public function getRealm() { 52 | return $this->properties['federation.realm']; 53 | } 54 | 55 | public function getReply() { 56 | return $this->properties['federation.reply']; 57 | } 58 | 59 | public function getTrustedIssuers() { 60 | return explode('|', $this->properties['federation.trustedissuers']); 61 | } 62 | 63 | public function getAudienceUris() { 64 | return explode('|', $this->properties['federation.audienceuris']); 65 | } 66 | } 67 | ?> 68 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/federation/FederatedLoginManager.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | authenticationObserver = $authenticationObserver; 43 | } 44 | 45 | public static function getFederatedLoginUrl($returnUrl) { 46 | return FederatedLoginManager :: getFederatedCustomLoginUrl(null, null, $returnUrl); 47 | } 48 | 49 | public static function getFederatedCustomLoginUrl($realm, $replyUrl, $returnUrl) { 50 | if ($realm == null) { 51 | $realm = FederatedConfiguration :: getInstance()->getRealm(); 52 | } 53 | 54 | if ($replyUrl == null) { 55 | $replyUrl = FederatedConfiguration :: getInstance()->getReply(); 56 | } 57 | 58 | return FederatedConfiguration :: getInstance()->getStsUrl() . '?wa=wsignin1.0&wtrealm=' . urlencode($realm) . '&wctx=' . urlencode($returnUrl) . '&id=passive&wreply=' . urlencode($replyUrl); 59 | } 60 | 61 | public function authenticate($token) { 62 | $validator = new Saml2TokenValidator(); 63 | 64 | $validator->allowedAudiences = $this->getAudienceUris(); 65 | $validator->trustedIssuers = $this->getTrustedIssuers(); 66 | $validator->thumbprints = $this->getThumprints(); 67 | $validator->validateAudiences = $this->validateAudiences; 68 | $validator->validateIssuer = $this->validateIssuer; 69 | $validator->validateExpiration = $this->validateExpiration; 70 | $claims = $validator->validate($token); 71 | 72 | $principal = new FederatedPrincipal($claims); 73 | $_SESSION[self::PRINCIPAL_SESSION_VARIABLE] = $principal; 74 | 75 | if (isset ($this->authenticationObserver)) 76 | $this->authenticationObserver->onAuthenticationSucceed($principal); 77 | 78 | 79 | header('Pragma: no-cache'); 80 | header('Cache-Control: no-cache, must-revalidate'); 81 | header("Location: " . $_POST['wctx'], true, 302); 82 | 83 | } 84 | 85 | public function getPrincipal() { 86 | return $_SESSION[self::PRINCIPAL_SESSION_VARIABLE]; 87 | } 88 | 89 | public function getClaims() { 90 | if ($this->isAuthenticated()) 91 | return $this->normalizeClaimList($this->getPrincipal()->getClaims()); 92 | } 93 | 94 | public function isAuthenticated() { 95 | return isset ($_SESSION[self::PRINCIPAL_SESSION_VARIABLE]); 96 | } 97 | 98 | protected function getAudienceUris() { 99 | if ($this->audience !== null) 100 | return array ( 101 | $this->audience 102 | ); 103 | else 104 | return FederatedConfiguration :: getInstance()->getAudienceUris(); 105 | } 106 | 107 | protected function getTrustedIssuers() { 108 | if ($this->trustedIssuer !== null) 109 | return array ( 110 | $this->trustedIssuer 111 | ); 112 | else 113 | return FederatedConfiguration :: getInstance()->getTrustedIssuers(); 114 | } 115 | 116 | protected function getThumprints() { 117 | if ($this->thumbprint !== null) 118 | return array ( 119 | $this->thumbprint 120 | ); 121 | else 122 | return array ( 123 | FederatedConfiguration :: getInstance()->getThumbprint() 124 | ); 125 | } 126 | 127 | private function normalizeClaimList($originalClaims) { 128 | assert('is_array($originalClaims)'); 129 | 130 | $claims = array (); 131 | if ($originalClaims !== null) { 132 | foreach ($originalClaims as $originalClaim) { 133 | foreach ($originalClaim->getClaimValues() as $claimValue) { 134 | array_push($claims, new Claim($originalClaim->claimType, $claimValue)); 135 | } 136 | } 137 | } 138 | 139 | return $claims; 140 | } 141 | } 142 | ?> 143 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/federation/FederatedPrincipal.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | claims = $claims; 32 | } 33 | 34 | public function getName() { 35 | foreach ($this->claims as $claim) { 36 | if (strcmp($claim->claimType, FederatedPrincipal :: NameClaimType) === 0) 37 | return $claim->claimValue; 38 | } 39 | 40 | foreach ($this->claims as $claim) { 41 | if (strcmp($claim->claimType, FederatedPrincipal :: EmailClaimType) === 0) 42 | return $claim->claimValue; 43 | } 44 | 45 | return ''; 46 | } 47 | 48 | public function getClaims() { 49 | return $this->claims; 50 | } 51 | } 52 | ?> 53 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/federation/IFederatedAuthenticationObserver.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | 28 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/federation/Saml2TokenValidator.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | parseToken($token); 53 | 54 | // validate digest and thumbprint 55 | $assertion = new SAML2_Assertion($data['Assertion']); 56 | $certificates = $assertion->getCertificates(); 57 | $this->validateCertificateThumbprint($certificates[0]); 58 | 59 | // validate issuer 60 | if ($this->validateIssuer) { 61 | $this->validateIssuer($assertion->getIssuer()); 62 | } 63 | 64 | // validate audiences 65 | if ($this->validateAudiences) { 66 | $this->validateAudiences($assertion->getValidAudiences(), $assertion->getNotBefore(), $assertion->getNotOnOrAfter()); 67 | } 68 | 69 | return $this->getClaims($data); 70 | } 71 | 72 | private function parseToken($token) { 73 | $dom = new DOMDocument(); 74 | $token = str_replace('\"', '"', $token); 75 | $dom->loadXML(str_replace("\r", "", $token)); 76 | 77 | $xpath = new DOMXpath($dom); 78 | $xpath->registerNamespace('wst', self :: NS_WS_TRUST); 79 | $xpath->registerNamespace('saml', SAML2_Const :: NS_SAML); 80 | 81 | $assertions = $xpath->query('/wst:RequestSecurityTokenResponse/wst:RequestedSecurityToken/saml:Assertion'); 82 | if ($assertions->length === 0) { 83 | $this->error('Received a response without an assertion on the WS-Fed PRP handler.'); 84 | } 85 | if ($assertions->length > 1) { 86 | $this->error('The WS-Fed PRP handler currently only supports a single assertion in a response.'); 87 | } 88 | $assertion = $assertions->item(0); 89 | 90 | return array ( 91 | 'Assertion' => $assertion, 92 | 'XPath' => $xpath 93 | ); 94 | } 95 | 96 | private function validateCertificateThumbprint($certificate) { 97 | $certFingerprint = strtolower(sha1(base64_decode($certificate))); 98 | 99 | foreach ($this->thumbprints as $tp) { 100 | if ($tp === $certFingerprint) { 101 | return; 102 | } 103 | } 104 | 105 | $this->error('Invalid fingerprint of certificate. Expected one of [' . implode('], [', $this->thumbprints) . '], but got [' . $certFingerprint . ']'); 106 | } 107 | 108 | private function validateIssuer($tokenIssuer) { 109 | $trustedIssuerOk = false; 110 | 111 | foreach ($this->trustedIssuers as $issuer) { 112 | $trustedIssuerOk = $trustedIssuerOk || (strcmp($tokenIssuer, $issuer) === 0); 113 | } 114 | 115 | if (!$trustedIssuerOk) 116 | $this->error('Invalid trusted issuer'); 117 | } 118 | 119 | private function validateAudiences($tokenAudiences, $notBefore, $notOnOrAfter) { 120 | 121 | if ($this->validateExpiration && !$this->checkDateIfExpired($notBefore, $notOnOrAfter)) { 122 | 123 | $this->error('The response has expired.'); 124 | } 125 | 126 | $audienceOk = false; 127 | 128 | foreach ($tokenAudiences as $tokenAudience) { 129 | foreach ($this->allowedAudiences as $allowedAudience) { 130 | $audienceOk = $audienceOk || (strcmp($allowedAudience, $tokenAudience) === 0); 131 | if ($audienceOk) 132 | break; 133 | } 134 | if ($audienceOk) 135 | break; 136 | } 137 | 138 | if (!$audienceOk) 139 | $this->error('Invalid audience'); 140 | } 141 | 142 | private function checkDateIfExpired($start = NULL, $end = NULL) { 143 | $currentTime = time(); 144 | $start -= 300; 145 | $end += 300; 146 | 147 | if (isset ($start)) { 148 | if (($start < 0) || ($start > $currentTime)) 149 | return false; 150 | } 151 | 152 | if (isset ($end)) { 153 | if (($end < 0) || ($end <= $currentTime)) 154 | return false; 155 | } 156 | 157 | return true; 158 | } 159 | 160 | private function getClaims($data) { 161 | $attributes = $data['XPath']->query('./saml:AttributeStatement/saml:Attribute', $data['Assertion']); 162 | 163 | $claims = array (); 164 | foreach ($attributes as $attribute) { 165 | array_push($claims, new Claim($attribute->getAttribute('Name'), $attribute->textContent)); 166 | } 167 | 168 | return $claims; 169 | } 170 | 171 | private function error($error) { 172 | throw new Exception("Error: " . $error); 173 | } 174 | } 175 | ?> 176 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/waad-federation/ConfigurableFederatedLoginManager.php: -------------------------------------------------------------------------------- 1 | 2 | /*----------------------------------------------------------------------- 3 | 4 | Copyright (c) Microsoft Corporation. All rights reserved. 5 | 6 | 7 | Copyright 2012 Microsoft Corporation 8 | All rights reserved. 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 16 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 17 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 18 | 19 | See the Apache Version 2.0 License for specific language governing 20 | permissions and limitations under the License. 21 | 22 | --------------------------------------------------------------------------- */ 23 | getTrustedIdentityProviderUrls(); 33 | 34 | if ($this->audience === null) { 35 | $repository = new TrustedIssuersRepository(); 36 | $trustedIssuers = $repository->getTrustedIdentityProviderUrls(); 37 | 38 | $mapSpn = function($issuer){ 39 | return($issuer->spn); 40 | }; 41 | 42 | return array_map($mapSpn, $trustedIssuers); 43 | } else { 44 | return FederatedConfiguration :: getInstance()->getAudienceUris(); 45 | } 46 | } 47 | } 48 | ?> 49 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/waad-federation/TrustedIssuer.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | name = $name; 34 | $this->displayName = $displayName; 35 | $this->spn = $spn; 36 | $this->replyUrl = $replyUrl; 37 | } 38 | 39 | public function getLoginUrl($returnUrl) { 40 | return FederatedLoginManager :: getFederatedCustomLoginUrl($this->spn, $this->replyUrl, $returnUrl); 41 | } 42 | } 43 | ?> -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/libraries/waad-federation/TrustedIssuersRepository.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | repositoryFileName = $this->getBasePath() . "/trustedIssuers.xml"; 32 | } else { 33 | $this->repositoryFileName = $repositoryFileName; 34 | } 35 | } 36 | 37 | private function GetBasePath() { 38 | return substr($_SERVER['SCRIPT_FILENAME'], 0, strlen($_SERVER['SCRIPT_FILENAME']) - strlen(strrchr($_SERVER['SCRIPT_FILENAME'], "\\"))); 39 | } 40 | 41 | public function getTrustedIdentityProviderUrls() { 42 | $xml = new XMLReader(); 43 | $xml->open($this->repositoryFileName); 44 | 45 | $trustedIssuers = array (); 46 | 47 | while ($xml->read()) { 48 | if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "issuer") { 49 | array_push($trustedIssuers, new TrustedIssuer($xml->getAttribute("name"), $xml->getAttribute("displayName"), $xml->getAttribute("realm"))); 50 | } 51 | } 52 | 53 | return $trustedIssuers; 54 | } 55 | 56 | public function getTrustedIdentityProviderUrl($name, $replyUrl) { 57 | $xml = new XMLReader(); 58 | $xml->open($this->repositoryFileName); 59 | 60 | $trustedIssuers = array (); 61 | 62 | while ($xml->read()) { 63 | if ($xml->nodeType == XMLReader::ELEMENT && $xml->name == "issuer" && $xml->getAttribute("name") == $name) { 64 | return new TrustedIssuer($xml->getAttribute("name"), $xml->getAttribute("displayName"), $xml->getAttribute("realm"), $replyUrl); 65 | } 66 | } 67 | 68 | return null; 69 | } 70 | } 71 | ?> -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/samples/.gitignore: -------------------------------------------------------------------------------- 1 | # placeholder -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/samples/phpSample/federation.ini: -------------------------------------------------------------------------------- 1 | federation.trustedissuers.issuer=https://accounts.accesscontrol.windows.net/v2/wsfederation 2 | federation.trustedissuers.thumbprint=3f5dfcdf4b3d0eab9ba49befb3cfd760da9cccf1 3 | federation.trustedissuers.friendlyname=Awesome Computers 4 | federation.audienceuris=spn:d184f6dd-d5d6-44c8-9cfa-e2d630dea392 5 | federation.realm=spn:d184f6dd-d5d6-44c8-9cfa-e2d630dea392@495c4a5e-38b7-49b9-a90f-4c0050b2d7f7 6 | federation.reply=https://localhost/phpSample/index.php -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/samples/phpSample/index.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | 25 | 26 | 27 | 28 | 29 | Index Page 30 | 31 | 32 |

Index Page

33 |

Welcome getPrincipal()->getName()); ?>!

34 | 35 |

Claim list:

36 | 43 | 44 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/samples/phpSample/login.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | 29 | 30 | 31 | 32 | 33 | Login Page 34 | 35 | 36 |

Login Page

37 | 48 | 49 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/samples/phpSample/secureResource.php: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------- 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | 6 | Copyright 2012 Microsoft Corporation 7 | All rights reserved. 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 15 | EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR 16 | CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. 17 | 18 | See the Apache Version 2.0 License for specific language governing 19 | permissions and limitations under the License. 20 | 21 | --------------------------------------------------------------------------- */ 22 | isAuthenticated()) { 35 | if (isset ($token)) { 36 | try { 37 | $loginManager->authenticate($token); 38 | } catch (Exception $e) { 39 | print_r($e->getMessage()); 40 | } 41 | } else { 42 | $returnUrl = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; 43 | 44 | header('Pragma: no-cache'); 45 | header('Cache-Control: no-cache, must-revalidate'); 46 | header("Location: https://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . "/login.php?returnUrl=" . $returnUrl, true, 302); 47 | exit(); 48 | } 49 | } 50 | ?> -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/code/samples/phpSample/trustedIssuers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/docs/Web SignOn with WAAD - PHP sample.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/azure-sdk-for-php-samples/05a18a54d77fbb1712312a2f615865916747dd2b/WAAD.WebSSO.PHP/php/docs/Web SignOn with WAAD - PHP sample.docx -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/scripts/CreateServicePrincipal.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/azure-sdk-for-php-samples/05a18a54d77fbb1712312a2f615865916747dd2b/WAAD.WebSSO.PHP/php/scripts/CreateServicePrincipal.ps1 -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/scripts/If your dll is missing-read this.txt: -------------------------------------------------------------------------------- 1 | 2 | PRE-REQUISITES BEFORE USING THIS SAMPLE 3 | 4 | ************************************************* 5 | 6 | Step 1: Create the Microsoft.Samples.Waad.PS.dll 7 | 8 | ************************************************* 9 | 10 | In order to use the PowerShell cmdlets provided under the %ROOT%/php/scripts/ directory, you will need to build the DLL that provides the WAAD functionality. 11 | 12 | We have included the source for building this DLL in this code for your convenience. It is located at: 13 | 14 | %ROOT%/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/ 15 | 16 | You have two options to build this DLL: 17 | 18 | 1. Build using VS 2010 Tools Command Line and included batch file 19 | 20 | You can build this DLL easily by running: 21 | 22 | %ROOT%/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS/buildWaadPS.bat 23 | 24 | This will build the DLL and copy the DLL to the correct location under %ROOT%/php/scripts/ 25 | 26 | 2. Load the .csproj file and build under Visual Studio 2010 or higher 27 | 28 | This is located under %ROOT%/csharp/code/libraries/powershell/Microsoft.Samples.Waad.PS. You will need to ensure that the Microsoft.Samples.Waad.PS.dll file is moved to the correct location under %ROOT%/csharp/scripts/ 29 | 30 | 31 | The rest of the setup instructions and walk-through are located at: 32 | 33 | http://www.windowsazure.com/en-us/develop/php/how-to-guides/web-sso/ 34 | -------------------------------------------------------------------------------- /WAAD.WebSSO.PHP/php/scripts/Microsoft.Samples.Waad.PS.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure/azure-sdk-for-php-samples/05a18a54d77fbb1712312a2f615865916747dd2b/WAAD.WebSSO.PHP/php/scripts/Microsoft.Samples.Waad.PS.lnk -------------------------------------------------------------------------------- /storage/BlockBlobExample.php: -------------------------------------------------------------------------------- 1 | setPrefix(CONTAINERNAME); 39 | $listContainersResult = $blobRestProxy->listContainers($listContainersOptions); 40 | $containerExists = false; 41 | foreach ($listContainersResult->getContainers() as $container) 42 | { 43 | if ($container->getName() == CONTAINERNAME) 44 | { 45 | // The container exists. 46 | $containerExists = true; 47 | // No need to keep checking. 48 | break; 49 | } 50 | } 51 | if (!$containerExists) 52 | { 53 | echo "Creating container.\n"; 54 | $blobRestProxy->createContainer(CONTAINERNAME); 55 | echo "Container '" . CONTAINERNAME . "' successfully created.\n"; 56 | } 57 | } 58 | 59 | try { 60 | 61 | echo "Beginning processing.\n"; 62 | 63 | /* 64 | Use CloudConfigurationManager::getConnectionString to retrieve 65 | the connection string whose name (in this example) is 66 | "StorageConnectionString". 67 | 68 | By default, the CloudConfigurationManager::getConnectionString method 69 | will look for an environment variable with the name that is passed in 70 | as the method parameter, and then assign the environment variable's 71 | value as the return value. 72 | 73 | For example, if you want to use the storage emulator, start 74 | the storage emulator, set an environment variable through a technique 75 | such as 76 | 77 | set StorageConnectionString=UseDevelopmentStorage=true 78 | 79 | and then run this sample at a command prompt that has the 80 | StorageConnectionString as an active environment variable. 81 | 82 | If you want to use a production storage account, set the 83 | environment variable through a technique such as 84 | 85 | set StorageConnectionString=DefaultEndpointsProtocol=http;AccountName=your_account_name;AccountKey=your_account_key 86 | 87 | (Substitute your storage account name and account key for 88 | your_account_name and your_account_key, respectively.) 89 | Then run this sample at a command prompt that has the 90 | StorageConnectionString as an active environment variable. 91 | 92 | The format for the storage connection string itself is documented at 93 | http://msdn.microsoft.com/en-us/library/windowsazure/ee758697.aspx 94 | 95 | If you do not want to use an environment variable as the source 96 | for the connection string name, you can register other sources 97 | via the CloudCofigurationManager::registerSource method. 98 | 99 | */ 100 | $connectionString = CloudConfigurationManager::getConnectionString("StorageConnectionString"); 101 | 102 | if (null == $connectionString || "" == $connectionString) 103 | { 104 | echo "Did not find a connection string whose name is 'StorageConnectionString'."; 105 | exit(); 106 | } 107 | 108 | $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); 109 | 110 | createContainerIfNotExists($blobRestProxy); 111 | 112 | echo "Using the '" . CONTAINERNAME . "' container and the '" . BLOCKBLOBNAME . "' blob.\n"; 113 | 114 | echo "Using file '" . FILENAME . "'\n"; 115 | 116 | if (!file_exists(FILENAME)) 117 | { 118 | echo "The '" . FILENAME . "' file does not exist. Exiting program.\n"; 119 | exit(); 120 | } 121 | 122 | $handle = fopen(FILENAME, "r"); 123 | 124 | // Upload the blob using blocks. 125 | $counter = 1; 126 | $blockIds = array(); 127 | 128 | while (!feof($handle)) 129 | { 130 | $blockId = str_pad($counter, PADLENGTH, "0", STR_PAD_LEFT); 131 | echo "Processing block $blockId.\n"; 132 | 133 | $block = new Block(); 134 | $block->setBlockId(base64_encode($blockId)); 135 | $block->setType("Uncommitted"); 136 | array_push($blockIds, $block); 137 | 138 | $data = fread($handle, BLOCKSIZE); 139 | 140 | // Upload the block. 141 | $blobRestProxy->createBlobBlock(CONTAINERNAME, BLOCKBLOBNAME, base64_encode($blockId), $data); 142 | $counter++; 143 | } 144 | 145 | // Done creating the blocks. Close the file and commit the blocks. 146 | fclose($handle); 147 | echo "Commiting the blocks.\n"; 148 | $blobRestProxy->commitBlobBlocks(CONTAINERNAME, BLOCKBLOBNAME, $blockIds); 149 | 150 | echo "Done processing.\n"; 151 | } 152 | catch(ServiceException $serviceException) 153 | { 154 | // Handle exception based on error codes and messages. 155 | // Error codes and messages are here: 156 | // http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx 157 | echo "ServiceException encountered.\n"; 158 | $code = $serviceException->getCode(); 159 | $error_message = $serviceException->getMessage(); 160 | echo "$code: $error_message"; 161 | } 162 | catch (Exception $exception) 163 | { 164 | echo "Exception encountered.\n"; 165 | $code = $exception->getCode(); 166 | $error_message = $exception->getMessage(); 167 | echo "$code: $error_message"; 168 | } 169 | 170 | ?> -------------------------------------------------------------------------------- /storage/PageBlobExample.php: -------------------------------------------------------------------------------- 1 | setPrefix(CONTAINERNAME); 38 | $listContainersResult = $blobRestProxy->listContainers($listContainersOptions); 39 | $containerExists = false; 40 | foreach ($listContainersResult->getContainers() as $container) 41 | { 42 | if ($container->getName() == CONTAINERNAME) 43 | { 44 | // The container exists. 45 | $containerExists = true; 46 | // No need to keep checking. 47 | break; 48 | } 49 | } 50 | if (!$containerExists) 51 | { 52 | echo "Creating container.\n"; 53 | $blobRestProxy->createContainer(CONTAINERNAME); 54 | echo "Container '" . CONTAINERNAME . "' successfully created.\n"; 55 | } 56 | } 57 | 58 | function createPageBlob($blobRestProxy) 59 | { 60 | 61 | echo "Creating page blob.\n"; 62 | $len = NUMPAGES * PAGESIZE; 63 | $blobRestProxy->createPageBlob(CONTAINERNAME, PAGEBLOBNAME, $len); 64 | echo "Page blob '" . PAGEBLOBNAME . "' successfully created with length $len.\n"; 65 | 66 | } 67 | 68 | function writeContent($blobRestProxy, $pageIndex, $createBlobPagesOptions) 69 | { 70 | echo "Writing to blob using page index $pageIndex.\n"; 71 | 72 | // Determine the page range. 73 | $start = $pageIndex * PAGESIZE; 74 | $end = $start + PAGESIZE - 1; 75 | $pageRange = new PageRange($start, $end); 76 | 77 | // Generate a random string of the desired length. 78 | $content = ""; 79 | for ($i = 0; $i < PAGESIZE; $i++) 80 | { 81 | // Create the string with random lowercase alphabet characters. 82 | $content .= chr(mt_rand(97, 122)); 83 | } 84 | 85 | $leaseID = $blobRestProxy->acquireLease(CONTAINERNAME, PAGEBLOBNAME)->getLeaseId(); 86 | echo "Acquired lease $leaseID.\n"; 87 | $createBlobPagesOptions->setLeaseId($leaseID); 88 | $blobRestProxy->createBlobPages(CONTAINERNAME, PAGEBLOBNAME, $pageRange, $content, $createBlobPagesOptions); 89 | $blobRestProxy->releaseLease(CONTAINERNAME, PAGEBLOBNAME, $leaseID); 90 | echo "Released lease $leaseID.\n"; 91 | echo "Wrote to blob.\n"; 92 | } 93 | 94 | function clearPages($blobRestProxy, $pageIndex, $numPages, $createBlobPagesOptions) 95 | { 96 | echo "Clearing page(s).\n"; 97 | $pageRange = new PageRange($pageIndex * PAGESIZE, ($pageIndex + $numPages) * PAGESIZE - 1); 98 | $leaseID = $blobRestProxy->acquireLease(CONTAINERNAME, PAGEBLOBNAME)->getLeaseId(); 99 | echo "Acquired lease $leaseID.\n"; 100 | $createBlobPagesOptions->setLeaseId($leaseID); 101 | $blobRestProxy->clearBlobPages(CONTAINERNAME, PAGEBLOBNAME, $pageRange, $createBlobPagesOptions); 102 | $blobRestProxy->releaseLease(CONTAINERNAME, PAGEBLOBNAME, $leaseID); 103 | echo "Released lease $leaseID.\n"; 104 | echo "Cleared $numPages page(s), beginning with page $pageIndex.\n"; 105 | } 106 | 107 | function showActiveRanges($blobRestProxy) 108 | { 109 | echo "Determining active ranges.\n"; 110 | $listPageRangesResult = $blobRestProxy->listPageBlobRanges(CONTAINERNAME, PAGEBLOBNAME); 111 | $ranges = $listPageRangesResult->getPageRanges(); 112 | if (0 == count($ranges)) 113 | { 114 | echo "No ranges are active.\n"; 115 | } 116 | else 117 | { 118 | echo "Active ranges: "; 119 | echo "< "; 120 | foreach ($ranges as $range) 121 | { 122 | echo "[" . $range->getStart() . " - " . $range->getEnd() . "] "; 123 | } 124 | echo " >\n"; 125 | } 126 | } 127 | 128 | function displayContents($blobRestProxy) 129 | { 130 | $getBlobResult = $blobRestProxy->getBlob(CONTAINERNAME, PAGEBLOBNAME); 131 | $stream = $getBlobResult->getContentStream(); 132 | echo "Displaying the blob contents.\n"; 133 | fpassthru($stream); 134 | fclose($stream); 135 | echo "\n"; 136 | } 137 | 138 | function deleteBlob($blobRestProxy) 139 | { 140 | echo "Deleting the blob.\n"; 141 | $blobRestProxy->deleteBlob(CONTAINERNAME, PAGEBLOBNAME); 142 | echo "Deleted the blob named '" . PAGEBLOBNAME . "' from the '" . CONTAINERNAME . "' container.\n"; 143 | } 144 | 145 | function waitForEnterKey() 146 | { 147 | // Prompt the user to press the Enter key. 148 | echo "Press Enter to continue. "; 149 | fgets(STDIN); 150 | 151 | // Add a blank link. 152 | echo "\n"; 153 | } 154 | 155 | try 156 | { 157 | echo "Beginning processing.\n"; 158 | 159 | /* 160 | Use CloudConfigurationManager::getConnectionString to retrieve 161 | the connection string whose name (in this example) is 162 | "StorageConnectionString". 163 | 164 | By default, the CloudConfigurationManager::getConnectionString method 165 | will look for an environment variable with the name that is passed in 166 | as the method parameter, and then assign the environment variable's 167 | value as the return value. 168 | 169 | For example, if you want to use the storage emulator, start 170 | the storage emulator, set an environment variable through a technique 171 | such as 172 | 173 | set StorageConnectionString=UseDevelopmentStorage=true 174 | 175 | and then run this sample at a command prompt that has the 176 | StorageConnectionString as an active environment variable. 177 | 178 | If you want to use a production storage account, set the 179 | environment variable through a technique such as 180 | 181 | set StorageConnectionString=DefaultEndpointsProtocol=http;AccountName=your_account_name;AccountKey=your_account_key 182 | 183 | (Substitute your storage account name and account key for 184 | your_account_name and your_account_key, respectively.) 185 | Then run this sample at a command prompt that has the 186 | StorageConnectionString as an active environment variable. 187 | 188 | The format for the storage connection string itself is documented at 189 | http://msdn.microsoft.com/en-us/library/windowsazure/ee758697.aspx 190 | 191 | If you do not want to use an environment variable as the source 192 | for the connection string name, you can register other sources 193 | via the CloudCofigurationManager::registerSource method. 194 | 195 | */ 196 | $connectionString = CloudConfigurationManager::getConnectionString("StorageConnectionString"); 197 | 198 | if (null == $connectionString || "" == $connectionString) 199 | { 200 | echo "Did not find a connection string whose name is 'StorageConnectionString'."; 201 | exit(); 202 | } 203 | 204 | $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); 205 | 206 | createContainerIfNotExists($blobRestProxy); 207 | 208 | echo "Using the '" . CONTAINERNAME . "' container and the '" . PAGEBLOBNAME . "' blob.\n"; 209 | 210 | $createBlobPagesOptions = new CreateBlobPagesOptions(); 211 | 212 | // Create the page blob. 213 | createPageBlob($blobRestProxy); 214 | waitForEnterKey(); 215 | 216 | // Show active ranges (there won't be any for a newly created blob). 217 | showActiveRanges($blobRestProxy); 218 | waitForEnterKey(); 219 | 220 | // Write to the blob, using the third page. The page index is zero-based. 221 | writeContent($blobRestProxy, 2, $createBlobPagesOptions); 222 | waitForEnterKey(); 223 | 224 | // Show active ranges. 225 | showActiveRanges($blobRestProxy); 226 | waitForEnterKey(); 227 | 228 | // Display the contents of the blob. 229 | displayContents($blobRestProxy); 230 | waitForEnterKey(); 231 | 232 | // Write to the blob again, using the first page. 233 | writeContent($blobRestProxy, 0, $createBlobPagesOptions); 234 | waitForEnterKey(); 235 | 236 | // Show active ranges. 237 | showActiveRanges($blobRestProxy); 238 | waitForEnterKey(); 239 | 240 | // Display the contents of the blob. 241 | displayContents($blobRestProxy); 242 | waitForEnterKey(); 243 | 244 | // Starting at the third page, clear one page. 245 | clearPages($blobRestProxy, 2, 1, $createBlobPagesOptions); 246 | waitForEnterKey(); 247 | 248 | // Show active ranges. 249 | showActiveRanges($blobRestProxy); 250 | waitForEnterKey(); 251 | 252 | // Display the contents of the blob. 253 | displayContents($blobRestProxy); 254 | waitForEnterKey(); 255 | 256 | // Delete the blob. 257 | // Comment this line out if you want to keep the blob. 258 | deleteBlob($blobRestProxy); 259 | 260 | echo "Exiting application.\n"; 261 | } 262 | catch(ServiceException $serviceException) 263 | { 264 | // Handle exception based on error codes and messages. 265 | // Error codes and messages are here: 266 | // http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx 267 | echo "ServiceException encountered.\n"; 268 | $code = $serviceException->getCode(); 269 | $error_message = $serviceException->getMessage(); 270 | echo "$code: $error_message"; 271 | } 272 | catch (Exception $exception) 273 | { 274 | echo "Exception encountered.\n"; 275 | $code = $exception->getCode(); 276 | $error_message = $exception->getMessage(); 277 | echo "$code: $error_message"; 278 | } 279 | 280 | ?> -------------------------------------------------------------------------------- /tasklist-mysql/additem.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasklist-mysql/createtable.php: -------------------------------------------------------------------------------- 1 | query($sql); 31 | } 32 | catch(Exception $e){ 33 | print_r($e); 34 | } 35 | 36 | echo "

Table created.

"; 37 | ?> -------------------------------------------------------------------------------- /tasklist-mysql/deleteitem.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasklist-mysql/getitems.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasklist-mysql/index.php: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | My ToDo List 19 | 39 | 40 | 41 |

My ToDo List

42 | 43 | 51 | 52 | Name 53 | Category 54 | Date 55 | Complete 56 | Mark Complete? 57 | Delete? 58 | "; 59 | foreach($items as $item) 60 | { 61 | echo " 62 | ".$item[1]." 63 | ".$item[2]." 64 | ".$item[3].""; 65 | 66 | if($item[4] == 0) 67 | { 68 | echo "No"; 69 | echo "Mark complete"; 70 | } 71 | else 72 | { 73 | echo "Yes"; 74 | echo "N/A"; 75 | } 76 | echo "Delete"; 77 | echo ""; 78 | } 79 | 80 | echo ""; 81 | } 82 | ?> 83 |
84 |
85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
Item Name:
Item Category:
Item Date (yyyy-mm-dd):
99 | 100 |
101 | 102 | -------------------------------------------------------------------------------- /tasklist-mysql/markitemcomplete.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasklist-mysql/taskmodel.php: -------------------------------------------------------------------------------- 1 | setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 26 | } 27 | catch(Exception $e){ 28 | die(print_r($e)); 29 | } 30 | return $conn; 31 | } 32 | 33 | function markItemComplete($item_id) 34 | { 35 | $conn = connect(); 36 | $sql = "UPDATE items SET is_complete = 1 WHERE id = ?"; 37 | $stmt = $conn->prepare($sql); 38 | $stmt->bindValue(1, $item_id); 39 | $stmt->execute(); 40 | } 41 | 42 | function getAllItems() 43 | { 44 | $conn = connect(); 45 | $sql = "SELECT * FROM items"; 46 | $stmt = $conn->query($sql); 47 | return $stmt->fetchAll(PDO::FETCH_NUM); 48 | } 49 | 50 | function addItem($name, $category, $date, $is_complete) 51 | { 52 | $conn = connect(); 53 | $sql = "INSERT INTO items (name, category, date, is_complete) VALUES (?, ?, ?, ?)"; 54 | $stmt = $conn->prepare($sql); 55 | $stmt->bindValue(1, $name); 56 | $stmt->bindValue(2, $category); 57 | $stmt->bindValue(3, $date); 58 | $stmt->bindValue(4, $is_complete); 59 | $stmt->execute(); 60 | } 61 | 62 | function deleteItem($item_id) 63 | { 64 | $conn = connect(); 65 | $sql = "DELETE FROM items WHERE id = ?"; 66 | $stmt = $conn->prepare($sql); 67 | $stmt->bindValue(1, $item_id); 68 | $stmt->execute(); 69 | } 70 | 71 | ?> -------------------------------------------------------------------------------- /tasklist-sqlazure/additem.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasklist-sqlazure/createtable.php: -------------------------------------------------------------------------------- 1 | query($sql); 31 | } 32 | catch(Exception $e){ 33 | print_r($e); 34 | } 35 | 36 | echo "

Table created.

"; 37 | ?> -------------------------------------------------------------------------------- /tasklist-sqlazure/deleteitem.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasklist-sqlazure/getitems.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasklist-sqlazure/index.php: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | My ToDo List 19 | 39 | 40 | 41 |

My ToDo List

42 | 43 | 51 | 52 | Name 53 | Category 54 | Date 55 | Complete 56 | Mark Complete? 57 | Delete? 58 | "; 59 | foreach($items as $item) 60 | { 61 | echo " 62 | ".$item[1]." 63 | ".$item[2]." 64 | ".$item[3].""; 65 | 66 | if($item[4] == 0) 67 | { 68 | echo "No"; 69 | echo "Mark complete"; 70 | } 71 | else 72 | { 73 | echo "Yes"; 74 | echo "N/A"; 75 | } 76 | echo "Delete"; 77 | echo ""; 78 | } 79 | 80 | echo ""; 81 | } 82 | ?> 83 |
84 |
85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 |
Item Name:
Item Category:
Item Date (yyyy-mm-dd):
99 | 100 |
101 | 102 | -------------------------------------------------------------------------------- /tasklist-sqlazure/markitemcomplete.php: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tasklist-sqlazure/taskmodel.php: -------------------------------------------------------------------------------- 1 | \sqlexpress"; 20 | $user = "user name"; 21 | $pwd = "password"; 22 | $db = "tasklist"; 23 | try{ 24 | $conn = new PDO( "sqlsrv:Server= $host ; Database = $db ", $user, $pwd); 25 | $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); 26 | } 27 | catch(Exception $e){ 28 | die(print_r($e)); 29 | } 30 | return $conn; 31 | } 32 | 33 | function markItemComplete($item_id) 34 | { 35 | $conn = connect(); 36 | $sql = "UPDATE items SET is_complete = 1 WHERE id = ?"; 37 | $stmt = $conn->prepare($sql); 38 | $stmt->bindValue(1, $item_id); 39 | $stmt->execute(); 40 | } 41 | 42 | function getAllItems() 43 | { 44 | $conn = connect(); 45 | $sql = "SELECT * FROM items"; 46 | $stmt = $conn->query($sql); 47 | return $stmt->fetchAll(PDO::FETCH_NUM); 48 | } 49 | 50 | function addItem($name, $category, $date, $is_complete) 51 | { 52 | $conn = connect(); 53 | $sql = "INSERT INTO items (name, category, date, is_complete) VALUES (?, ?, ?, ?)"; 54 | $stmt = $conn->prepare($sql); 55 | $stmt->bindValue(1, $name); 56 | $stmt->bindValue(2, $category); 57 | $stmt->bindValue(3, $date); 58 | $stmt->bindValue(4, $is_complete); 59 | $stmt->execute(); 60 | } 61 | 62 | function deleteItem($item_id) 63 | { 64 | $conn = connect(); 65 | $sql = "DELETE FROM items WHERE id = ?"; 66 | $stmt = $conn->prepare($sql); 67 | $stmt->bindValue(1, $item_id); 68 | $stmt->execute(); 69 | } 70 | 71 | ?> --------------------------------------------------------------------------------