Implement user authentication

Learn how to implement to access a secure ArcGIS with .

Prerequisites

Before starting this tutorial:

  1. You need an ArcGIS Location Platform or ArcGIS Online account.

  2. Your system meets the system requirements.

Steps

  1. Go to the Create OAuth credentials for user authentication tutorial to obtain a ClientID and RedirectURL to use in step 3.

  2. Add the ArcGIS Toolkit package to this swift project by following these instructions.

  3. In the Project Navigator, click MainApp.swift.

    • In the Editor, declare and initialize an Authenticator toolkit member in the MainApp struct.
    • Create an initializer in the MainApp struct.
    • Create a new instance of the Authenticator using an OAuthUserConfiguration that contains your OAuth credentials from step 1.
    • Ensure the ArcGISEnvironment.authenticationManager uses the authenticatior to handle any ArcGIS challenges.
    MainApp.swift.
    7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
    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
    29
    30
    31
    32
    33
    34
    @main
    struct MainApp: App {
    
        @ObservedObject var authenticator: Authenticator
    
        init() {
    
            authenticator = Authenticator(oAuthUserConfigurations: [
                OAuthUserConfiguration(
    
                    portalURL: URL(string: "<#YOUR-PORTAL-URL#>")!,
                    clientID: ""<#YOUR-CLIENT-ID#>"",
                    redirectURL: URL(string: "<#YOUR-REDIRECT-URL#>")!
    
                )
            ])
            ArcGISEnvironment.authenticationManager.handleChallenges(using: authenticator)
    
        }
    

For more information, see the User authentication.

Best Practice: The OAuth credentials are stored directly in the code as a convenience for this tutorial. In a production environment we do not recommend that you store it directly in source code.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.

You can no longer sign into this site. Go to your ArcGIS portal or the ArcGIS Location Platform dashboard to perform management tasks.

Your ArcGIS portal

Create, manage, and access API keys and OAuth 2.0 developer credentials, hosted layers, and data services.

Your ArcGIS Location Platform dashboard

Manage billing, monitor service usage, and access additional resources.

Learn more about these changes in the What's new in Esri Developers June 2024 blog post.

Close