├── DISCLAIMER ├── LICENSE ├── NAPPS ├── NAPPS.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── pmeyer.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── pmeyer.xcuserdatad │ │ └── xcschemes │ │ ├── NAPPS.xcscheme │ │ └── xcschememanagement.plist └── NAPPS │ ├── AppDelegate.swift │ ├── Assets.xcassets │ └── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── PIC-152x152-red.png │ │ ├── PIC-29x29-red.png │ │ ├── PIC-40x40-red.png │ │ ├── PIC-58x58-red.png │ │ ├── PIC-76x76-red.png │ │ └── PIC-80x80-red.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── ProtocolHelper.swift │ ├── SessionManager.swift │ └── ViewController.swift └── README.md /DISCLAIMER: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * Copyright (C) 2014 Ping Identity Corporation 3 | * All rights reserved. 4 | * 5 | * Ping Identity Corporation 6 | * 1099 18th St Suite 2950 7 | * Denver, CO 80202 8 | * 303.468.2900 9 | * http://www.pingidentity.com 10 | * 11 | * DISCLAIMER OF WARRANTIES: 12 | * 13 | * THE SOFTWARE PROVIDED HEREUNDER IS PROVIDED ON AN "AS IS" BASIS, WITHOUT 14 | * ANY WARRANTIES OR REPRESENTATIONS EXPRESS, IMPLIED OR STATUTORY; INCLUDING, 15 | * WITHOUT LIMITATION, WARRANTIES OF QUALITY, PERFORMANCE, NONINFRINGEMENT, 16 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. NOR ARE THERE ANY 17 | * WARRANTIES CREATED BY A COURSE OR DEALING, COURSE OF PERFORMANCE OR TRADE 18 | * USAGE. FURTHERMORE, THERE ARE NO WARRANTIES THAT THE SOFTWARE WILL MEET 19 | * YOUR NEEDS OR BE FREE FROM ERRORS, OR THAT THE OPERATION OF THE SOFTWARE 20 | * WILL BE UNINTERRUPTED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR 21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES HOWEVER CAUSED AND ON ANY THEORY OF 23 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 | 203 | -------------------------------------------------------------------------------- /NAPPS/NAPPS.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F024FFA41B8E26D5006885A8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F024FFA31B8E26D5006885A8 /* AppDelegate.swift */; }; 11 | F024FFA61B8E26D5006885A8 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F024FFA51B8E26D5006885A8 /* ViewController.swift */; }; 12 | F024FFA91B8E26D5006885A8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F024FFA71B8E26D5006885A8 /* Main.storyboard */; }; 13 | F024FFAB1B8E26D5006885A8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F024FFAA1B8E26D5006885A8 /* Assets.xcassets */; }; 14 | F024FFAE1B8E26D5006885A8 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F024FFAC1B8E26D5006885A8 /* LaunchScreen.storyboard */; }; 15 | F024FFB71B8E378A006885A8 /* ProtocolHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F024FFB51B8E378A006885A8 /* ProtocolHelper.swift */; }; 16 | F024FFB81B8E378A006885A8 /* SessionManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = F024FFB61B8E378A006885A8 /* SessionManager.swift */; }; 17 | F05736781C0CABCE007AD3E5 /* README.md in Sources */ = {isa = PBXBuildFile; fileRef = F05736771C0CABCE007AD3E5 /* README.md */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | F024FFA01B8E26D5006885A8 /* NAPPS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NAPPS.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | F024FFA31B8E26D5006885A8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 23 | F024FFA51B8E26D5006885A8 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 24 | F024FFA81B8E26D5006885A8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 25 | F024FFAA1B8E26D5006885A8 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26 | F024FFAD1B8E26D5006885A8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | F024FFAF1B8E26D5006885A8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | F024FFB51B8E378A006885A8 /* ProtocolHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ProtocolHelper.swift; sourceTree = ""; }; 29 | F024FFB61B8E378A006885A8 /* SessionManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SessionManager.swift; sourceTree = ""; }; 30 | F05736771C0CABCE007AD3E5 /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../../README.md; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | F024FF9D1B8E26D5006885A8 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | F024FF971B8E26D5006885A8 = { 45 | isa = PBXGroup; 46 | children = ( 47 | F024FFA21B8E26D5006885A8 /* NAPPS */, 48 | F024FFA11B8E26D5006885A8 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | F024FFA11B8E26D5006885A8 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | F024FFA01B8E26D5006885A8 /* NAPPS.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | F024FFA21B8E26D5006885A8 /* NAPPS */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | F05736771C0CABCE007AD3E5 /* README.md */, 64 | F024FFB51B8E378A006885A8 /* ProtocolHelper.swift */, 65 | F024FFB61B8E378A006885A8 /* SessionManager.swift */, 66 | F024FFA31B8E26D5006885A8 /* AppDelegate.swift */, 67 | F024FFA51B8E26D5006885A8 /* ViewController.swift */, 68 | F024FFA71B8E26D5006885A8 /* Main.storyboard */, 69 | F024FFAA1B8E26D5006885A8 /* Assets.xcassets */, 70 | F024FFAC1B8E26D5006885A8 /* LaunchScreen.storyboard */, 71 | F024FFAF1B8E26D5006885A8 /* Info.plist */, 72 | ); 73 | path = NAPPS; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | F024FF9F1B8E26D5006885A8 /* NAPPS */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = F024FFB21B8E26D5006885A8 /* Build configuration list for PBXNativeTarget "NAPPS" */; 82 | buildPhases = ( 83 | F024FF9C1B8E26D5006885A8 /* Sources */, 84 | F024FF9D1B8E26D5006885A8 /* Frameworks */, 85 | F024FF9E1B8E26D5006885A8 /* Resources */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = NAPPS; 92 | productName = NAPPS; 93 | productReference = F024FFA01B8E26D5006885A8 /* NAPPS.app */; 94 | productType = "com.apple.product-type.application"; 95 | }; 96 | /* End PBXNativeTarget section */ 97 | 98 | /* Begin PBXProject section */ 99 | F024FF981B8E26D5006885A8 /* Project object */ = { 100 | isa = PBXProject; 101 | attributes = { 102 | LastUpgradeCheck = 0700; 103 | ORGANIZATIONNAME = "Ping Identity"; 104 | TargetAttributes = { 105 | F024FF9F1B8E26D5006885A8 = { 106 | CreatedOnToolsVersion = 7.0; 107 | }; 108 | }; 109 | }; 110 | buildConfigurationList = F024FF9B1B8E26D5006885A8 /* Build configuration list for PBXProject "NAPPS" */; 111 | compatibilityVersion = "Xcode 3.2"; 112 | developmentRegion = English; 113 | hasScannedForEncodings = 0; 114 | knownRegions = ( 115 | en, 116 | Base, 117 | ); 118 | mainGroup = F024FF971B8E26D5006885A8; 119 | productRefGroup = F024FFA11B8E26D5006885A8 /* Products */; 120 | projectDirPath = ""; 121 | projectRoot = ""; 122 | targets = ( 123 | F024FF9F1B8E26D5006885A8 /* NAPPS */, 124 | ); 125 | }; 126 | /* End PBXProject section */ 127 | 128 | /* Begin PBXResourcesBuildPhase section */ 129 | F024FF9E1B8E26D5006885A8 /* Resources */ = { 130 | isa = PBXResourcesBuildPhase; 131 | buildActionMask = 2147483647; 132 | files = ( 133 | F024FFAE1B8E26D5006885A8 /* LaunchScreen.storyboard in Resources */, 134 | F024FFAB1B8E26D5006885A8 /* Assets.xcassets in Resources */, 135 | F024FFA91B8E26D5006885A8 /* Main.storyboard in Resources */, 136 | ); 137 | runOnlyForDeploymentPostprocessing = 0; 138 | }; 139 | /* End PBXResourcesBuildPhase section */ 140 | 141 | /* Begin PBXSourcesBuildPhase section */ 142 | F024FF9C1B8E26D5006885A8 /* Sources */ = { 143 | isa = PBXSourcesBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | F024FFA61B8E26D5006885A8 /* ViewController.swift in Sources */, 147 | F024FFA41B8E26D5006885A8 /* AppDelegate.swift in Sources */, 148 | F05736781C0CABCE007AD3E5 /* README.md in Sources */, 149 | F024FFB81B8E378A006885A8 /* SessionManager.swift in Sources */, 150 | F024FFB71B8E378A006885A8 /* ProtocolHelper.swift in Sources */, 151 | ); 152 | runOnlyForDeploymentPostprocessing = 0; 153 | }; 154 | /* End PBXSourcesBuildPhase section */ 155 | 156 | /* Begin PBXVariantGroup section */ 157 | F024FFA71B8E26D5006885A8 /* Main.storyboard */ = { 158 | isa = PBXVariantGroup; 159 | children = ( 160 | F024FFA81B8E26D5006885A8 /* Base */, 161 | ); 162 | name = Main.storyboard; 163 | sourceTree = ""; 164 | }; 165 | F024FFAC1B8E26D5006885A8 /* LaunchScreen.storyboard */ = { 166 | isa = PBXVariantGroup; 167 | children = ( 168 | F024FFAD1B8E26D5006885A8 /* Base */, 169 | ); 170 | name = LaunchScreen.storyboard; 171 | sourceTree = ""; 172 | }; 173 | /* End PBXVariantGroup section */ 174 | 175 | /* Begin XCBuildConfiguration section */ 176 | F024FFB01B8E26D5006885A8 /* Debug */ = { 177 | isa = XCBuildConfiguration; 178 | buildSettings = { 179 | ALWAYS_SEARCH_USER_PATHS = NO; 180 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 181 | CLANG_CXX_LIBRARY = "libc++"; 182 | CLANG_ENABLE_MODULES = YES; 183 | CLANG_ENABLE_OBJC_ARC = YES; 184 | CLANG_WARN_BOOL_CONVERSION = YES; 185 | CLANG_WARN_CONSTANT_CONVERSION = YES; 186 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 187 | CLANG_WARN_EMPTY_BODY = YES; 188 | CLANG_WARN_ENUM_CONVERSION = YES; 189 | CLANG_WARN_INT_CONVERSION = YES; 190 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 191 | CLANG_WARN_UNREACHABLE_CODE = YES; 192 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 193 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 194 | COPY_PHASE_STRIP = NO; 195 | DEBUG_INFORMATION_FORMAT = dwarf; 196 | ENABLE_STRICT_OBJC_MSGSEND = YES; 197 | ENABLE_TESTABILITY = YES; 198 | GCC_C_LANGUAGE_STANDARD = gnu99; 199 | GCC_DYNAMIC_NO_PIC = NO; 200 | GCC_NO_COMMON_BLOCKS = YES; 201 | GCC_OPTIMIZATION_LEVEL = 0; 202 | GCC_PREPROCESSOR_DEFINITIONS = ( 203 | "DEBUG=1", 204 | "$(inherited)", 205 | ); 206 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 207 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 208 | GCC_WARN_UNDECLARED_SELECTOR = YES; 209 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 210 | GCC_WARN_UNUSED_FUNCTION = YES; 211 | GCC_WARN_UNUSED_VARIABLE = YES; 212 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 213 | MTL_ENABLE_DEBUG_INFO = YES; 214 | ONLY_ACTIVE_ARCH = YES; 215 | SDKROOT = iphoneos; 216 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 217 | TARGETED_DEVICE_FAMILY = 2; 218 | }; 219 | name = Debug; 220 | }; 221 | F024FFB11B8E26D5006885A8 /* Release */ = { 222 | isa = XCBuildConfiguration; 223 | buildSettings = { 224 | ALWAYS_SEARCH_USER_PATHS = NO; 225 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 226 | CLANG_CXX_LIBRARY = "libc++"; 227 | CLANG_ENABLE_MODULES = YES; 228 | CLANG_ENABLE_OBJC_ARC = YES; 229 | CLANG_WARN_BOOL_CONVERSION = YES; 230 | CLANG_WARN_CONSTANT_CONVERSION = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_EMPTY_BODY = YES; 233 | CLANG_WARN_ENUM_CONVERSION = YES; 234 | CLANG_WARN_INT_CONVERSION = YES; 235 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 236 | CLANG_WARN_UNREACHABLE_CODE = YES; 237 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 238 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 239 | COPY_PHASE_STRIP = NO; 240 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 241 | ENABLE_NS_ASSERTIONS = NO; 242 | ENABLE_STRICT_OBJC_MSGSEND = YES; 243 | GCC_C_LANGUAGE_STANDARD = gnu99; 244 | GCC_NO_COMMON_BLOCKS = YES; 245 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 246 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 247 | GCC_WARN_UNDECLARED_SELECTOR = YES; 248 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 249 | GCC_WARN_UNUSED_FUNCTION = YES; 250 | GCC_WARN_UNUSED_VARIABLE = YES; 251 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 252 | MTL_ENABLE_DEBUG_INFO = NO; 253 | SDKROOT = iphoneos; 254 | TARGETED_DEVICE_FAMILY = 2; 255 | VALIDATE_PRODUCT = YES; 256 | }; 257 | name = Release; 258 | }; 259 | F024FFB31B8E26D5006885A8 /* Debug */ = { 260 | isa = XCBuildConfiguration; 261 | buildSettings = { 262 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 263 | INFOPLIST_FILE = NAPPS/Info.plist; 264 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 265 | PRODUCT_BUNDLE_IDENTIFIER = com.pingidentity.developer.NAPPS; 266 | PRODUCT_NAME = "$(TARGET_NAME)"; 267 | }; 268 | name = Debug; 269 | }; 270 | F024FFB41B8E26D5006885A8 /* Release */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 274 | INFOPLIST_FILE = NAPPS/Info.plist; 275 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 276 | PRODUCT_BUNDLE_IDENTIFIER = com.pingidentity.developer.NAPPS; 277 | PRODUCT_NAME = "$(TARGET_NAME)"; 278 | }; 279 | name = Release; 280 | }; 281 | /* End XCBuildConfiguration section */ 282 | 283 | /* Begin XCConfigurationList section */ 284 | F024FF9B1B8E26D5006885A8 /* Build configuration list for PBXProject "NAPPS" */ = { 285 | isa = XCConfigurationList; 286 | buildConfigurations = ( 287 | F024FFB01B8E26D5006885A8 /* Debug */, 288 | F024FFB11B8E26D5006885A8 /* Release */, 289 | ); 290 | defaultConfigurationIsVisible = 0; 291 | defaultConfigurationName = Release; 292 | }; 293 | F024FFB21B8E26D5006885A8 /* Build configuration list for PBXNativeTarget "NAPPS" */ = { 294 | isa = XCConfigurationList; 295 | buildConfigurations = ( 296 | F024FFB31B8E26D5006885A8 /* Debug */, 297 | F024FFB41B8E26D5006885A8 /* Release */, 298 | ); 299 | defaultConfigurationIsVisible = 0; 300 | defaultConfigurationName = Release; 301 | }; 302 | /* End XCConfigurationList section */ 303 | }; 304 | rootObject = F024FF981B8E26D5006885A8 /* Project object */; 305 | } 306 | -------------------------------------------------------------------------------- /NAPPS/NAPPS.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NAPPS/NAPPS.xcodeproj/project.xcworkspace/xcuserdata/pmeyer.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingidentity/ios-napps-sample-application/c0de8ff4ef62e289cbbc47ff146dd3c3f405b5c8/NAPPS/NAPPS.xcodeproj/project.xcworkspace/xcuserdata/pmeyer.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /NAPPS/NAPPS.xcodeproj/xcuserdata/pmeyer.xcuserdatad/xcschemes/NAPPS.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /NAPPS/NAPPS.xcodeproj/xcuserdata/pmeyer.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | NAPPS.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | F024FF9F1B8E26D5006885A8 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /NAPPS/NAPPS/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // 4 | 5 | import UIKit 6 | 7 | @UIApplicationMain 8 | class AppDelegate: UIResponder, UIApplicationDelegate { 9 | 10 | var window: UIWindow? 11 | 12 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 13 | // Override point for customization after application launch. 14 | return true 15 | } 16 | 17 | func applicationWillResignActive(application: UIApplication) { 18 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 19 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 20 | } 21 | 22 | func applicationDidEnterBackground(application: UIApplication) { 23 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 24 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 25 | } 26 | 27 | func applicationWillEnterForeground(application: UIApplication) { 28 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 29 | } 30 | 31 | func applicationDidBecomeActive(application: UIApplication) { 32 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 33 | } 34 | 35 | func applicationWillTerminate(application: UIApplication) { 36 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 37 | } 38 | 39 | func application(application: UIApplication, handleOpenURL url: NSURL) -> Bool { 40 | 41 | print("*** Received application callback ***") 42 | print("Application callback URL received: \(url.absoluteString)") 43 | 44 | // If the callback was for the OpenID Connect authentication, then handle the response 45 | let baseUrl = url.absoluteString.componentsSeparatedByString("?")[0] 46 | if baseUrl.lowercaseString == app_redirect_uri.lowercaseString { 47 | 48 | // Close the SFSafariViewController 49 | window!.rootViewController?.presentedViewController?.dismissViewControllerAnimated(true , completion: nil) 50 | 51 | // Kick off the authentication flow (see ProtocolHelper.swift) 52 | SessionManager.currentSession.inErrorState = false; 53 | SessionManager.currentSession.isAuthenticated = false; 54 | handleAuthorizationResponse(url) 55 | } 56 | return true 57 | } 58 | } 59 | 60 | -------------------------------------------------------------------------------- /NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "size" : "29x29", 5 | "idiom" : "ipad", 6 | "filename" : "PIC-29x29-red.png", 7 | "scale" : "1x" 8 | }, 9 | { 10 | "size" : "29x29", 11 | "idiom" : "ipad", 12 | "filename" : "PIC-58x58-red.png", 13 | "scale" : "2x" 14 | }, 15 | { 16 | "size" : "40x40", 17 | "idiom" : "ipad", 18 | "filename" : "PIC-40x40-red.png", 19 | "scale" : "1x" 20 | }, 21 | { 22 | "size" : "40x40", 23 | "idiom" : "ipad", 24 | "filename" : "PIC-80x80-red.png", 25 | "scale" : "2x" 26 | }, 27 | { 28 | "size" : "76x76", 29 | "idiom" : "ipad", 30 | "filename" : "PIC-76x76-red.png", 31 | "scale" : "1x" 32 | }, 33 | { 34 | "size" : "76x76", 35 | "idiom" : "ipad", 36 | "filename" : "PIC-152x152-red.png", 37 | "scale" : "2x" 38 | } 39 | ], 40 | "info" : { 41 | "version" : 1, 42 | "author" : "xcode" 43 | } 44 | } -------------------------------------------------------------------------------- /NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-152x152-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingidentity/ios-napps-sample-application/c0de8ff4ef62e289cbbc47ff146dd3c3f405b5c8/NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-152x152-red.png -------------------------------------------------------------------------------- /NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-29x29-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingidentity/ios-napps-sample-application/c0de8ff4ef62e289cbbc47ff146dd3c3f405b5c8/NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-29x29-red.png -------------------------------------------------------------------------------- /NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-40x40-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingidentity/ios-napps-sample-application/c0de8ff4ef62e289cbbc47ff146dd3c3f405b5c8/NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-40x40-red.png -------------------------------------------------------------------------------- /NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-58x58-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingidentity/ios-napps-sample-application/c0de8ff4ef62e289cbbc47ff146dd3c3f405b5c8/NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-58x58-red.png -------------------------------------------------------------------------------- /NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-76x76-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingidentity/ios-napps-sample-application/c0de8ff4ef62e289cbbc47ff146dd3c3f405b5c8/NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-76x76-red.png -------------------------------------------------------------------------------- /NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-80x80-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pingidentity/ios-napps-sample-application/c0de8ff4ef62e289cbbc47ff146dd3c3f405b5c8/NAPPS/NAPPS/Assets.xcassets/AppIcon.appiconset/PIC-80x80-red.png -------------------------------------------------------------------------------- /NAPPS/NAPPS/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /NAPPS/NAPPS/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 26 | 27 | 28 | This is a basic sample application to demonstrate using the iOS9 SFSafariViewController browser component to enable SSO across multiple native applications. This application also demonstrates using OpenID Connect to authenticate a user and, leveraging OAuth 2.0, make an API call to the UserInfo endpoint to retrieve user profile information. 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 60 | 70 | 80 | 90 | 96 | 102 | 108 | 114 | 120 | 126 | 132 | 138 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /NAPPS/NAPPS/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleURLTypes 22 | 23 | 24 | CFBundleTypeRole 25 | Editor 26 | CFBundleURLName 27 | com.pingidentity.developer.NAPPS 28 | CFBundleURLSchemes 29 | 30 | com.pingidentity.developer.NAPPS 31 | 32 | 33 | 34 | CFBundleVersion 35 | 1 36 | LSRequiresIPhoneOS 37 | 38 | UILaunchStoryboardName 39 | LaunchScreen 40 | UIMainStoryboardFile 41 | Main 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations~ipad 47 | 48 | UIInterfaceOrientationPortrait 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /NAPPS/NAPPS/ProtocolHelper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ProtocolHelper.swift 3 | // 4 | // NOTE: These functions are best left to a library to implement. They are included here in a basic form to provide detail around the steps 5 | // involved with implementing these protocol functions. 6 | 7 | 8 | import Foundation 9 | 10 | // Configuration Settings 11 | let claims_userName:String! = "sub" 12 | 13 | let pf_baseUrl:String! = "https://sso.pingdevelopers.com" 14 | let authz_url:String! = "/as/authorization.oauth2" 15 | let token_url:String! = "/as/token.oauth2" 16 | let userinfo_url:String! = "/idp/userinfo.openid" 17 | 18 | let scope:String! = "openid profile email" 19 | let issuer:String! = "https://sso.pingdevelopers.com" 20 | let client_id:String! = "ac_client" 21 | let app_redirect_uri:String! = "com.pingidentity.developer.napps://oidc_callback" 22 | 23 | let acr_valueOptions = ["urn:acr:form", "urn:acr:x509", "urn:acr:google", "urn:acr:basic", "urn:acr:saml"] 24 | 25 | 26 | // OpenID Connect / OAuth 2.0 helper functions 27 | 28 | // Helper function - Build the authorization request URL 29 | func buildAuthorizationUrl(prompt: String = "") -> String { 30 | 31 | print("*** Building authorization URL ***") 32 | 33 | // these two parameters MUST be unique values per request to tie the request to the application that requested it 34 | SessionManager.currentSession.state = NSUUID().UUIDString 35 | SessionManager.currentSession.code_challenge = NSUUID().UUIDString 36 | 37 | var authorizationParameters = Dictionary() 38 | 39 | authorizationParameters["client_id"] = client_id 40 | authorizationParameters["response_type"] = "code" 41 | authorizationParameters["code_challenge"] = SessionManager.currentSession.code_challenge 42 | authorizationParameters["redirect_uri"] = SessionManager.currentSession.redirect_uri 43 | authorizationParameters["scope"] = scope 44 | authorizationParameters["state"] = SessionManager.currentSession.state 45 | authorizationParameters["acr_values"] = SessionManager.currentSession.acr_values 46 | if(!prompt.isEmpty) { 47 | authorizationParameters["prompt"] = prompt 48 | } 49 | 50 | let authorizationUrl = pf_baseUrl + authz_url + "?" + queryStringFromDictionary(authorizationParameters) 51 | return authorizationUrl 52 | } 53 | 54 | // Authentication step 1 - process the authorization response 55 | func handleAuthorizationResponse(url: NSURL) { 56 | 57 | print("*** Processing the authorization response ***") 58 | 59 | let queryItems = parseAttributes(url.query!, asType: ParseDataType.QueryString) 60 | 61 | if let tempError = queryItems["error"] { 62 | SessionManager.currentSession.inErrorState = true 63 | SessionManager.currentSession.error_code = tempError as? String 64 | 65 | if let tempErrorDescription = queryItems["error_description"] { 66 | SessionManager.currentSession.error_description = tempErrorDescription.stringByReplacingOccurrencesOfString("+", withString: " ").stringByRemovingPercentEncoding! 67 | } 68 | } 69 | 70 | // Check that the state matches the value we sent in the request 71 | if queryItems["state"] as? String != SessionManager.currentSession.state { 72 | SessionManager.currentSession.inErrorState = true 73 | SessionManager.currentSession.error_description = "State mismatch" 74 | return 75 | } 76 | 77 | if let tempCode = queryItems["code"] { 78 | SessionManager.currentSession.code = tempCode as? String 79 | } 80 | 81 | if !SessionManager.currentSession.inErrorState { 82 | 83 | // Move to step 2 - swap the authorization code for the tokens 84 | swapAuthorizationCodeForTokens() 85 | } else { 86 | 87 | // There was an error during the authorization request 88 | NSNotificationCenter.defaultCenter().postNotificationName("AuthenticationFailed", object: nil) 89 | } 90 | } 91 | 92 | // Authentication step 2 - Swap the authorization code for the tokens (access_token, id_token & (optional) refresh_token) 93 | func swapAuthorizationCodeForTokens() { 94 | 95 | print("*** Exchanging the authorization code for the tokens ***") 96 | 97 | // Build the request to the token endpoint 98 | let tokenUrl = pf_baseUrl + token_url 99 | 100 | var postParameters = Dictionary() 101 | postParameters["client_id"] = client_id 102 | postParameters["grant_type"] = "authorization_code" 103 | postParameters["code_verifier"] = SessionManager.currentSession.code_challenge 104 | postParameters["code"] = SessionManager.currentSession.code 105 | postParameters["redirect_uri"] = SessionManager.currentSession.redirect_uri 106 | let postData = queryStringFromDictionary(postParameters) 107 | 108 | // POST request to the token endpoint 109 | print("Performing token request (POST) to \(tokenUrl) with data \(postData)") 110 | 111 | let tokenRequest = NSMutableURLRequest(URL: NSURL(string: tokenUrl)!) 112 | tokenRequest.HTTPMethod = "POST" 113 | tokenRequest.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding) 114 | 115 | let httpRequest = NSURLSession.sharedSession().dataTaskWithRequest(tokenRequest) { 116 | data, response, error in 117 | 118 | // A client-side error occured 119 | if error != nil { 120 | SessionManager.currentSession.inErrorState = true 121 | SessionManager.currentSession.error_description = (error?.description)! 122 | return 123 | } 124 | 125 | let responseCode = (response as! NSHTTPURLResponse).statusCode 126 | let responseData = NSString(data: data!, encoding: NSUTF8StringEncoding) 127 | print("Received Response (\(responseCode)): \(responseData)") 128 | 129 | let responseItems = parseAttributes(responseData!, asType: ParseDataType.JSON) 130 | 131 | // 200 - Successful token exchange 132 | if responseCode == 200 { 133 | 134 | if let tempAccessToken = responseItems["access_token"] { 135 | SessionManager.currentSession.access_token = tempAccessToken as? String 136 | } 137 | 138 | if let tempIdToken = responseItems["id_token"] { 139 | SessionManager.currentSession.id_token = tempIdToken as? String 140 | } 141 | 142 | if let tempRefreshToken = responseItems["refresh_token"] { 143 | SessionManager.currentSession.refresh_token = tempRefreshToken as? String 144 | } 145 | // 400 - Token exchange failed 146 | } else if responseCode == 400 { 147 | 148 | SessionManager.currentSession.inErrorState = true 149 | 150 | if let errorResult = responseItems["error"] { 151 | SessionManager.currentSession.error_code = errorResult as? String 152 | SessionManager.currentSession.error_description = responseItems["error_description"] as? String 153 | } 154 | } 155 | 156 | if !SessionManager.currentSession.inErrorState { 157 | 158 | // Move to step 3 - Validate the ID Token 159 | validateIdToken() 160 | } else { 161 | print("!!! An error occurred: \(SessionManager.currentSession.error_code) !!!") 162 | // An error occured during the HTTP request to the token endpoint 163 | NSNotificationCenter.defaultCenter().postNotificationName("AuthenticationFailed", object: nil) 164 | } 165 | } 166 | httpRequest.resume() 167 | } 168 | 169 | // Authentication step 3 - Validate the id_token to retrieve the authenticated user subject 170 | func validateIdToken() { 171 | 172 | print("*** Validating the ID token ***") 173 | 174 | // Note: We are using the OpenID Connect Basic Profile and because we got the id_token direct from the token endpoint, we don't need to validate the signature 175 | // id_token is a JWT which is [header].[payload].[signature] - we are only concerned with the payload contents 176 | // iOS doesn't have a base64urldecode function so we need to "convert" the base64urlencoded string to a base64encoded string 177 | let idTokenPayloadString = base64EncodedStringFromBase64UrlEncodedString(SessionManager.currentSession.id_token!.componentsSeparatedByString(".")[1]) 178 | 179 | let idTokenPayload = NSString(data: NSData(base64EncodedString: idTokenPayloadString, options: NSDataBase64DecodingOptions.IgnoreUnknownCharacters)!, encoding: NSUTF8StringEncoding) 180 | let idTokenAttributes = parseAttributes(idTokenPayload!, asType: ParseDataType.JSON) 181 | 182 | // Check the issuer matches the issuer 183 | if idTokenAttributes["iss"] as? String != issuer { 184 | let idTokenIssuer = idTokenAttributes["iss"] 185 | print("Error: Invalid issuer - \(idTokenIssuer) != \(issuer)") 186 | SessionManager.currentSession.inErrorState = true 187 | SessionManager.currentSession.error_description = "Invalid Issuer" 188 | } 189 | 190 | // Check the audience matches the client_id 191 | if idTokenAttributes["aud"] as? String != client_id { 192 | let idTokenAudience = idTokenAttributes["aud"] 193 | print("Error: Invalid audience - \(idTokenAudience) != \(client_id)") 194 | SessionManager.currentSession.inErrorState = true 195 | SessionManager.currentSession.error_description = "Invalid Audience" 196 | } 197 | 198 | // Check the token hasn't expired 199 | if idTokenAttributes["exp"] != nil { 200 | let expires = NSDate(timeIntervalSince1970: idTokenAttributes["exp"] as! Double) 201 | 202 | if expires.compare(NSDate()) == NSComparisonResult.OrderedAscending { 203 | print("Error: ID token has expired") 204 | SessionManager.currentSession.inErrorState = true 205 | SessionManager.currentSession.error_description = "Token Expired" 206 | } 207 | } 208 | 209 | // Store the subject of the id_token (to compare later against the userinfo data) 210 | if let tempIdTokenSubject = idTokenAttributes["sub"] { 211 | SessionManager.currentSession.subject = tempIdTokenSubject as? String 212 | } 213 | 214 | if !SessionManager.currentSession.inErrorState { 215 | 216 | // Move to step 4 - Query the UserInfo endpoint to retrieve additional attributes 217 | queryUserInfoEndpoint() 218 | } else { 219 | print("!!! An error occurred: \(SessionManager.currentSession.error_code) !!!") 220 | // An error occurred validating the id_token 221 | NSNotificationCenter.defaultCenter().postNotificationName("AuthenticationFailed", object: nil) 222 | } 223 | } 224 | 225 | // Authentication step 4 (optional) - Query the UserInfo endpoint to retrieve additional attributes about the user 226 | func queryUserInfoEndpoint() { 227 | 228 | print("*** Querying the UserInfo endpoint ***") 229 | 230 | let userInfoUrl = pf_baseUrl + userinfo_url 231 | 232 | // Form a GET request using the OAuth access_token as Bearer credentials 233 | let userInfoRequest = NSMutableURLRequest(URL: NSURL(string: userInfoUrl)!) 234 | userInfoRequest.HTTPMethod = "GET" 235 | userInfoRequest.setValue("Bearer \(SessionManager.currentSession.access_token!)", forHTTPHeaderField: "Authorization") 236 | 237 | print("Set Authorization header to: Bearer \(SessionManager.currentSession.access_token!)") 238 | 239 | let httpRequest = NSURLSession.sharedSession().dataTaskWithRequest(userInfoRequest) { 240 | data, response, error in 241 | 242 | if error != nil { 243 | print("HTTP Request Error: \(error)") 244 | SessionManager.currentSession.inErrorState = true 245 | SessionManager.currentSession.error_description = (error?.description)! 246 | return 247 | } 248 | 249 | let responseCode = (response as! NSHTTPURLResponse).statusCode 250 | let responseData = NSString(data: data!, encoding: NSUTF8StringEncoding) 251 | print("Received Response (\(responseCode)): \(responseData)") 252 | 253 | SessionManager.currentSession.rawUserInfoResponse = responseData as? String 254 | let userInfoAttributes = parseAttributes(SessionManager.currentSession.rawUserInfoResponse!, asType: ParseDataType.JSON) 255 | 256 | if !SessionManager.currentSession.inErrorState { 257 | 258 | // The subject of the id_token MUST match the subject of the UserInfo claims 259 | if userInfoAttributes["sub"] as? String != SessionManager.currentSession.subject { 260 | 261 | SessionManager.currentSession.inErrorState = true 262 | SessionManager.currentSession.error_description = "UserInfo does not match id_token" 263 | 264 | NSNotificationCenter.defaultCenter().postNotificationName("AuthenticationFailed", object: nil) 265 | } else { 266 | 267 | // Thats it! We have an authenticated user and their attributes 268 | SessionManager.currentSession.isAuthenticated = true 269 | SessionManager.currentSession.userAttributes = userInfoAttributes 270 | 271 | // Notify listeners that an authentication event is complete 272 | NSNotificationCenter.defaultCenter().postNotificationName("AuthenticationComplete", object: nil) 273 | } 274 | } else { 275 | print("!!! An error occurred: \(SessionManager.currentSession.error_code) !!!") 276 | // An error occurred querying the UserInfo endpoint 277 | NSNotificationCenter.defaultCenter().postNotificationName("AuthenticationFailed", object: nil) 278 | } 279 | } 280 | httpRequest.resume() 281 | } 282 | 283 | func refreshOAuthAccessToken() { 284 | 285 | print("*** Refreshing the OAuth access token ***") 286 | 287 | // Build the request to the token endpoint 288 | let tokenUrl = pf_baseUrl + token_url 289 | 290 | var postParameters = Dictionary() 291 | postParameters["client_id"] = client_id 292 | postParameters["grant_type"] = "refresh_token" 293 | postParameters["refresh_token"] = SessionManager.currentSession.refresh_token 294 | let postData = queryStringFromDictionary(postParameters) 295 | 296 | // POST request to the token endpoint 297 | print("Performing token request (POST) to \(tokenUrl) with data \(postData)") 298 | 299 | let tokenRequest = NSMutableURLRequest(URL: NSURL(string: tokenUrl)!) 300 | tokenRequest.HTTPMethod = "POST" 301 | tokenRequest.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding) 302 | 303 | let httpRequest = NSURLSession.sharedSession().dataTaskWithRequest(tokenRequest) { 304 | data, response, error in 305 | 306 | // A client-side error occured 307 | if error != nil { 308 | SessionManager.currentSession.inErrorState = true 309 | SessionManager.currentSession.error_description = (error?.description)! 310 | return 311 | } 312 | 313 | let responseCode = (response as! NSHTTPURLResponse).statusCode 314 | let responseData = NSString(data: data!, encoding: NSUTF8StringEncoding) 315 | print("Received Response (\(responseCode)): \(responseData)") 316 | 317 | let responseItems = parseAttributes(responseData!, asType: ParseDataType.JSON) 318 | 319 | // 200 - Successful token request 320 | if responseCode == 200 { 321 | 322 | if let tempAccessToken = responseItems["access_token"] { 323 | SessionManager.currentSession.access_token = tempAccessToken as? String 324 | } 325 | 326 | if let tempIdToken = responseItems["id_token"] { 327 | SessionManager.currentSession.id_token = tempIdToken as? String 328 | } 329 | 330 | if let tempRefreshToken = responseItems["refresh_token"] { 331 | SessionManager.currentSession.refresh_token = tempRefreshToken as? String 332 | } 333 | 334 | // 400 - Token request failed 335 | } else if responseCode == 400 { 336 | 337 | SessionManager.currentSession.inErrorState = true 338 | 339 | if let errorResult = responseItems["error"] { 340 | SessionManager.currentSession.error_code = errorResult as? String 341 | SessionManager.currentSession.error_description = responseItems["error_description"] as? String 342 | } 343 | } 344 | 345 | if !SessionManager.currentSession.inErrorState { 346 | 347 | // Notify that the request succeeded so we can refresh the view 348 | NSNotificationCenter.defaultCenter().postNotificationName("AuthenticationComplete", object: nil) 349 | } else { 350 | print("!!! An error occurred: \(SessionManager.currentSession.error_code) !!!") 351 | // An error occured during the HTTP request to the token endpoint 352 | NSNotificationCenter.defaultCenter().postNotificationName("AuthenticationFailed", object: nil) 353 | } 354 | } 355 | httpRequest.resume() 356 | } 357 | 358 | 359 | // General utility functions 360 | 361 | enum ParseDataType { 362 | case QueryString 363 | case JSON 364 | } 365 | 366 | //This function is to simplify the building of the querystring and form post body. 367 | func queryStringFromDictionary(dictionary:Dictionary) -> String { 368 | 369 | 370 | var queryString = "" 371 | var firstParam = true 372 | 373 | for queryParam in dictionary.keys { 374 | if (!firstParam) { queryString += "&" } // if this is not the first param, pre-pend by & 375 | let encodedParam = queryParam.stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet()); 376 | let encodedValue = (dictionary[queryParam] as! String).stringByAddingPercentEncodingWithAllowedCharacters(.URLHostAllowedCharacterSet()) 377 | 378 | queryString += "\(encodedParam!)=\(encodedValue!)" 379 | firstParam = false 380 | } 381 | 382 | return queryString 383 | } 384 | 385 | //This function is to simplify parsing of a querystring or JSON response into a dictionary 386 | func parseAttributes(fromStringData:NSString, asType:ParseDataType) -> [String: AnyObject] { 387 | 388 | var returnDictionary = [String: AnyObject]() 389 | 390 | if asType == ParseDataType.QueryString { 391 | for queryParam in fromStringData.componentsSeparatedByString("&") { 392 | print("Parsing query parameter: \(queryParam)") 393 | var queryElement = queryParam.componentsSeparatedByString("=") 394 | returnDictionary[queryElement[0]] = queryElement[1] 395 | } 396 | } else { 397 | print("Parsing JSON data: \(fromStringData)") 398 | let jsonData = fromStringData.dataUsingEncoding(NSUTF8StringEncoding) 399 | do { 400 | returnDictionary = try (NSJSONSerialization.JSONObjectWithData(jsonData!, options: NSJSONReadingOptions.MutableContainers) as? [String: AnyObject])! 401 | } catch { 402 | print("Error - \(error)") 403 | } 404 | } 405 | 406 | return returnDictionary 407 | } 408 | 409 | // iOS supports base64 encoding and decoding however not base64URl encoding and decoding this covers that gap 410 | func base64EncodedStringFromBase64UrlEncodedString(base64UrlEncodedString:String) -> String { 411 | 412 | // Add padding to the end of the string 413 | var numEqualsNeeded = 4 - (base64UrlEncodedString.characters.count % 4) 414 | if (numEqualsNeeded == 4) { numEqualsNeeded = 0; } 415 | var padding = "" 416 | 417 | for var i = 0; i < numEqualsNeeded; ++i { 418 | padding += "=" 419 | } 420 | 421 | // Replace _ with / and - with + 422 | let base64EncodedString = base64UrlEncodedString.stringByReplacingOccurrencesOfString("_", withString: "/").stringByReplacingOccurrencesOfString("-", withString: "+") + padding 423 | 424 | return base64EncodedString 425 | } 426 | -------------------------------------------------------------------------------- /NAPPS/NAPPS/SessionManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SessionManager.swift 3 | // 4 | 5 | import Foundation 6 | 7 | // Helper utility to maintain a user "session" inside the application. This is for demo purposes only (best practise would be to store the tokens in the keychain etc) 8 | 9 | class SessionManager { 10 | 11 | var issuer:String? 12 | var client_id:String? 13 | 14 | var state:String? 15 | var code_challenge:String? 16 | var acr_values = "urn:acr:form" 17 | var redirect_uri = app_redirect_uri 18 | 19 | var code:String? 20 | 21 | var access_token:String? 22 | var refresh_token:String? 23 | var id_token:String? 24 | 25 | var isAuthenticated = false 26 | var inErrorState = false 27 | var error_code:String? 28 | var error_description:String? 29 | var subject:String? 30 | 31 | var rawUserInfoResponse:String? 32 | var userAttributes = [String : AnyObject]() 33 | 34 | // Singleton to store the "current" session 35 | static let currentSession = SessionManager() 36 | 37 | func signout() { 38 | 39 | issuer = "" 40 | client_id = "" 41 | 42 | state = "" 43 | code_challenge = "" 44 | acr_values = "urn:acr:form" 45 | redirect_uri = app_redirect_uri 46 | 47 | code = "" 48 | 49 | access_token = "" 50 | refresh_token = "" 51 | id_token = "" 52 | 53 | isAuthenticated = false 54 | inErrorState = false 55 | error_description = "" 56 | subject = "" 57 | 58 | rawUserInfoResponse = "" 59 | userAttributes = [:] 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /NAPPS/NAPPS/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // 4 | 5 | import UIKit 6 | import SafariServices 7 | 8 | class ViewController: UIViewController, SFSafariViewControllerDelegate { 9 | 10 | @IBOutlet weak var labelAuthenticationResult: UILabel! 11 | @IBOutlet weak var labelSubject: UILabel! 12 | @IBOutlet weak var textviewIdToken: UITextView! 13 | @IBOutlet weak var textviewAccessToken: UITextView! 14 | @IBOutlet weak var textviewRefreshToken: UITextView! 15 | 16 | @IBOutlet weak var buttonSignIn: UIButton! 17 | @IBOutlet weak var buttonSignInSilently: UIButton! 18 | @IBOutlet weak var buttonRefreshAccessToken: UIButton! 19 | @IBOutlet weak var buttonCallUserInfo: UIButton! 20 | 21 | @IBAction func actionSignIn() { 22 | 23 | let authorizationUrl = buildAuthorizationUrl() 24 | print("*** Using SFSafariViewController to redirect user to authorization url: \(authorizationUrl) ***") 25 | 26 | // Present a SFSafariViewController to handle the websso flow 27 | let safariVC = SFSafariViewController(URL: NSURL(string: authorizationUrl)!) 28 | safariVC.delegate = self 29 | presentViewController(safariVC, animated: true, completion: nil) 30 | } 31 | 32 | @IBAction func actionSignInSilently() { 33 | 34 | // do a prompt=none re-auth 35 | let authorizationUrl = buildAuthorizationUrl("none") 36 | print("*** Using an invisible SFSafariViewController to redirect user to authorization url: \(authorizationUrl) ***") 37 | 38 | // Present an invisible SFSafariViewController to handle the websso flow 39 | let safariVC = SFSafariViewController(URL: NSURL(string: authorizationUrl)!) 40 | safariVC.delegate = self 41 | safariVC.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext 42 | safariVC.view.alpha = 0.0 43 | presentViewController(safariVC, animated: false, completion: nil) 44 | } 45 | 46 | @IBAction func actionRefreshAccessToken() { 47 | 48 | refreshOAuthAccessToken() 49 | } 50 | 51 | @IBAction func actionCallUserInfo() { 52 | 53 | queryUserInfoEndpoint() 54 | 55 | let userInfoPopup = UIAlertController(title: "UserInfo Results", message: SessionManager.currentSession.rawUserInfoResponse, preferredStyle: UIAlertControllerStyle.Alert) 56 | userInfoPopup.addAction(UIAlertAction(title: "Close", style: UIAlertActionStyle.Default,handler: nil)) 57 | 58 | self.presentViewController(userInfoPopup, animated: true, completion: nil) 59 | } 60 | 61 | func updateView() { 62 | 63 | print("*** Updating the view ***") 64 | 65 | if (SessionManager.currentSession.inErrorState) { 66 | labelAuthenticationResult.text = SessionManager.currentSession.error_code 67 | labelAuthenticationResult.textColor = UIColor.redColor() 68 | } else { 69 | 70 | if (SessionManager.currentSession.isAuthenticated) { 71 | labelAuthenticationResult.text = "Authentication Sucessful" 72 | labelAuthenticationResult.textColor = UIColor.greenColor() 73 | } else { 74 | labelAuthenticationResult.text = "Please Sign In below..." 75 | labelAuthenticationResult.textColor = UIColor.blackColor() 76 | } 77 | } 78 | 79 | if (SessionManager.currentSession.isAuthenticated) { 80 | labelSubject.text = SessionManager.currentSession.userAttributes[claims_userName] as? String 81 | textviewAccessToken.text = SessionManager.currentSession.access_token 82 | textviewIdToken.text = SessionManager.currentSession.id_token 83 | textviewRefreshToken.text = SessionManager.currentSession.refresh_token 84 | 85 | buttonRefreshAccessToken.enabled = true 86 | buttonCallUserInfo.enabled = true 87 | 88 | } else { 89 | 90 | labelSubject.text = "[Not Logged In]" 91 | textviewAccessToken.text = "[Not Logged In]" 92 | textviewIdToken.text = "[Not Logged In]" 93 | textviewRefreshToken.text = "[Not Logged In]" 94 | 95 | buttonRefreshAccessToken.enabled = false 96 | buttonCallUserInfo.enabled = false 97 | } 98 | self.view.setNeedsDisplay() 99 | } 100 | 101 | 102 | //Functions triggered when authentication events occur 103 | func authenticationComplete() { 104 | 105 | dispatch_async(dispatch_get_main_queue(), { 106 | self.updateView() 107 | }) 108 | } 109 | 110 | func authenticationFailed() { 111 | 112 | dispatch_async(dispatch_get_main_queue(), { 113 | self.updateView() 114 | }) 115 | } 116 | 117 | 118 | //UIViewController Delegates 119 | override func viewDidLoad() { 120 | super.viewDidLoad() 121 | 122 | NSNotificationCenter.defaultCenter().addObserver(self, selector: "authenticationComplete", name: "AuthenticationComplete", object: nil) 123 | NSNotificationCenter.defaultCenter().addObserver(self, selector: "authenticationFailed", name: "AuthenticationFailed", object: nil) 124 | 125 | self.updateView() 126 | } 127 | 128 | override func didReceiveMemoryWarning() { 129 | super.didReceiveMemoryWarning() 130 | } 131 | } 132 | 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iOS9 Native Application SSO Sample Application 2 | 3 | **ios-napps-sample-application** is a basic sample application to demonstrate using the new SFSafariViewController in iOS9 to facilitate native application single sign-on. 4 | 5 | This sample application will authenticate the user via OpenID Connect 1.0 and present the user's subject and tokens on the screen. Options to refresh the OAuth 2.0 access token and to refresh the authentication session are also demonstrated. 6 | 7 | Refer to the **Mobile Application SSO Developers Guide** at https://developer.pingidentity.com/en/resources/napps-native-app-sso for more detailed information. 8 | 9 | 10 | ## Installation 11 | 12 | This sample application has been built using PingFederate 8.0.1 and the OAuth Playground 3.2. Follow the documentation for PingFederate and the OAuth Playground to quickly stand up an OpenID Connect Provider / OAuth Authorization Server. 13 | 14 | Modify the OAuth client "ac_client" in the PingFederate configuration (OAuth Settings -> Client Management -> ac_client -> Redirect URIs) to include the application callback URI (com.pingidentity.developer.napps://oidc_callback) defined in the "ProtocolHelper.swift" file. 15 | 16 | Modify the "ProtocolHelper.swift" file with the URL of your PingFederate server and the name of your issuer. 17 | 18 | Note: Due to the Application Transport Security (ATS) feature of iOS9, your PingFederate server must have a valid SSL certificate. 19 | 20 | 21 | ## Disclaimer 22 | 23 | *This software is open sourced by Ping Identity but not supported commercially as such. Any questions/issues/comments should be directed to the "Developer Q&A" group in the Ping Identity Support Communities https://community.pingidentity.com/collaborate.* 24 | --------------------------------------------------------------------------------