{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"OAuth on iOS using the Swift SDK","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"oauth-on-ios-using-the-swift-sdk","__idx":0},"children":["OAuth on iOS using the Swift SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This guide is for an app developer who needs to integrate with Zephr’s OAuth social sign-in."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"prerequisites","__idx":1},"children":["Prerequisites"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Configure the OAuth client ID and secret for the providers you are using, details on how to can be found on the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://knowledgecenter.zuora.com/Zephr/Zephr_Classic_User_Guide/G_Integrations/OAuth_2.0","title":"OAuth 2.0"},"children":["OAuth 2.0 page"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Add the iOS redirect URI to your Zephr Site (UI for this pending)."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This should be either:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["An app-claimed https URL redirection e.g. ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://myapp.com/oauthredirect"},"children":["https://myapp.com/oauthredirect"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["A custom URL scheme e.g. ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["my-app:/oauthRedirect"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Add the Zephr OAuth callback address to your OAuth providers allowed redirects list."," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["GET https://mysite.com/zephr/oauth/<provider>/ios/callback"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The Zephr Swift SDK can be used to make integration with the Zephr Public API simpler in your app. The SDK can be found on BitBucket ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://bitbucket.org/blaizeinc/swift-sdk"},"children":["here"]},"."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"implementation","__idx":2},"children":["Implementation"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Start the OAuth flow by retrieving the authentication URL for your chosen provider."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["A list of providers and how to configure them can be found on the ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"/zephr-docs/zephr-api/zephr-api-tutorials/on-site-oauth-with-the-public-api/","title":"On-site OAuth with the Public API"},"children":["OAuth with the Public API page"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example startOAuthFlow call:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"swift","header":{"controls":{"copy":{}}},"source":"BlaizePublic.client.startOAuthFlow(provider: AuthProvider) { result in\n    switch result {\n    case .success(let locationUrl):\n        // Trigger OAuth flow\n    case .failure:\n        // Handle failure\n    }\n}\n","lang":"swift"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Using the location URL returned by ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["startOAuthFlow"]},", start an ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["ASWebAuthenticationSession"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Details can be found at ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://developer.apple.com/documentation/authenticationservices/aswebauthenticationsession"},"children":["ASWebAuthenticationSession"]},"."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This will cause the app to launch a webview with the providers OAuth page for the user to authenticate and will return a ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["callbackURL"]}," when the configured ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["callbackURLScheme"]}," is found."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["There are 3 possible outcomes from the OAuth flow callback:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Login successful"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Partial Registration"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Failure"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"login-successful","__idx":3},"children":["Login Successful"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If the user either already exists in the Zephr User store or if there are no required registration fields, a user will be successfully logged in and a Zephr session ID will be returned."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example response:"," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<redirecturi>?action=login&status=success&tracking_id=1234&session_id=1234"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"partial-registration","__idx":4},"children":["Partial Registration"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If the user accepts the authentication request but Zephr does not have all the information to create the account in the Zephr User store, a partial registration will return a state key that can be used to fully register a user with the missing registration fields."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example response:"," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<redirecturi>?action=register&status=partial&state_key=1234&identifier=user@example.com"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Using the state_key returned by the callback, the required fields can be sent to fully register a user."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"swift","header":{"controls":{"copy":{}}},"source":"BlaizePublic.client.register(token: token, attributes: \\[...\\]) { result in\n    switch result {\n    case .success(let sessionId):\n        print(\"Registration successful\")\n        // Save the sessionId\n    case .userAlreadyExists:\n        print(\"Error: user already exists\")\n    case .emailDomainBlacklisted:\n        print(\"Error: email domain blacklisted\")\n    case .badRequest:\n        print(\"Error: bad registration request\")\n    }\n}\n","lang":"swift"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":3,"id":"failure","__idx":5},"children":["Failure"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The user denied the authentication request or something went wrong."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Example response:"," ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["<redirecturi>?action=login&status=failure&message=..."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["An example of how to handle the Zephr OAuth callback responses in Swift follows:"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"swift","header":{"controls":{"copy":{}}},"source":"switch callbackURL?.queryItems\\[\"status\"\\] {\ncase \"success\":\n    print(\"Login successful\")\n    setUserSessionId(sessionId: queryItems\\[\"session\\_id\"\\])\ncase \"partial\":\n    print(\"Partial registration successful\")\n    triggerPartialRegistration(token: queryItems\\[\"state\\_key\"\\])\ncase \"failure\":\n    print(\"Auth response error\")\n    print(queryItems\\[\"message\"\\] ?? \"\")\ndefault:\n    print(\"Unknown auth response status\")\n    print (callbackURL!)\n}\n","lang":"swift"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["An example login Swift project is available ",{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://bitbucket.org/blaizeinc/zephr-ios-oauth-example"},"children":["here"]}," for reference."]}]},"headings":[{"value":"OAuth on iOS using the Swift SDK","id":"oauth-on-ios-using-the-swift-sdk","depth":1},{"value":"Prerequisites","id":"prerequisites","depth":2},{"value":"Implementation","id":"implementation","depth":2},{"value":"Login Successful","id":"login-successful","depth":3},{"value":"Partial Registration","id":"partial-registration","depth":3},{"value":"Failure","id":"failure","depth":3}],"frontmatter":{"seo":{"title":"OAuth on iOS using the Swift SDK"}},"lastModified":"2026-02-19T12:25:42.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/zephr-docs/zephr-sdk/zephr-sdk-tutorials/oauth-on-ios-using-the-swift-sdk","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}