-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update docs to match developers site
- Loading branch information
1 parent
cdf4434
commit 585b642
Showing
12 changed files
with
50 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
docs/auth/connecting-to-a-portal_files/execute-results/html.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"hash": "ec0de991bdf483a718483f14688bcada", | ||
"result": { | ||
"engine": "knitr", | ||
"markdown": "---\ntitle: \"Connect to your Portal\"\nuid: authenticating-with-r\n---\n\n\n\n\nIn order to create content, interact with non-public items, save geocoding results, or use POI data with the Places Service, you will need to authenticate through ArcGIS Online, ArcGIS Enterprise, or Platform. \n\n:::{.callout-tip title=\"ArcGIS Sharing model\" collapse=\"true\"}\nItems in ArcGIS Online and ArcGIS Enterprise can be unshared (accessible only to the item owner) or shared to groups, your organization, or everyone (<span style=\"display:inline-block; width: 50%;\"><img src=\"../shared/images/sharing-public.png\" width=50%/></span>). [Learn more about Sharing here.](https://doc.arcgis.com/en/arcgis-online/share-maps/share-items.htm) Read and write access to an item is controlled by the owner-specified sharing level, organizational security settings, and the accessing user's [privileges](https://doc.arcgis.com/en/arcgis-online/administer/roles.htm).\n:::\n\n\n## Using OAuth2\n\nThere are two ways to authorize with [OAuth2](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2.0/): either by using a a `code` or a `client` flow. Code-based authorization is interactive, requiring you to copy an authorization code from a browser window into the R console during the execution of your code. Client authorization allows for non-interactive scripting, but cannot be used for creating or modifying content. In most cases, code-based authorization is recommended. These two methods are explained below. \n\nBefore you can authorize with either OAuth2 method, you must first create a client ID. \n\n## Obtaining a Client ID\n\nIf a client ID is not provided to you by an administrator and you have the ability to create content items, you can create one. \n\nYou can do so by creating an application item. \n\n- Log in to your ArcGIS Online or ArcGIS Enterprise organization\n- Navigate to the Content tab\n- Click `New Item`\n- Select `Application` \n\n![](../shared/images/content-app.png){width=50%}\n\n- Choose `Other application` as your `Application Type`\n- Give the item an informative name such as `r-arcgis`\n - Optionally, specify the folder, tags, and summary as well.\n\n![](../shared/images/new-item.png){width=50%}\n\n- You will be directed to the item details page of the newly created application where you can see your credentials. **Do not share these**.\n\n![](../shared/images/credentials.png){width=50%}\n\n\n### Authorizing\n\nFirst, load the library. \n\n```r\nlibrary(arcgis)\n#> Attaching core arcgis packages:\n#> - {arcgisutils} v0.1.0\n#> - {arcgislayers} v0.1.0\n```\n\n#### Code flow\n\nThe OAuth2 Code Flow is a process where a user authorizes an application to act on their behalf by granting a temporary access token. This type of authorization permits the application to take actions on the user's behalf for the duration of the access token. Learn more about how [ArcGIS uses OAuth2.0](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/oauth-2/).\n\nRunning `auth_code()` will open a tab in your browser to begin the code flow. If you are authorizing to an ArcGIS Enterprise portal, ensure that you set the `ARCGIS_HOST` environment variable correctly and that you have restarted your R session. \n\n```r\ntoken <- auth_code()\n```\nYou will be prompted to sign in to your portal. \n\n![](../shared/images/oauth-sign-in.png){width=50%}\n\nOnce you've signed in, copy the code that appears, and return to R. Enter the code into the console without any modifications and press enter. \n\n![](../shared/images/oauth-code.png){width=70%}\n\nYour authorization will have completed. \n\n```r\ntoken\n#> <httr2_token>\n#> token_type: bearer\n#> access_token: <REDACTED>\n#> expires_at: 2023-03-03 13:21:40\n#> refresh_token: <REDACTED>\n#> username: your-user\n#> ssl: TRUE\n#> refresh_token_expires_in: 1209599\n```\n\n:::{.callout-warning}\nAuthorization tokens are temporary and will expire. If you encounter an invalid token error, you might need to generate a new token.\n:::\n\nTo make this token easily accessible to `{arcgis}`, use `set_arc_token()` which sets the token in dedicated authorization token environment.\n\n```r\nset_arc_token(token)\n```\n\n\n#### Client flow\n\nAlternatively, you can authorize using the client OAuth2 flow. This will authorize the application you created and not ourselves. Because of this, you cannot use the client flow to create or modify content. \n\nThe client flow has the benefit of being non-interactive, though. \n\n```r\ntoken <- auth_client()\nset_arc_token(token)\n```\n\n## Using a Named User\n\nAuthorizing using an ArcGIS Online or ArcGIS Enterprise [username and password](https://developers.arcgis.com/documentation/mapping-apis-and-services/security/user-authentication/direct-username-password/) is a legacy method that is supported for cases where OAuth2 is not implemented. As a reminder, credentials should never be stored in plaintext in code.\n\n:::{.callout-important}\n**Security consideration**: Obtaining an access token with this method will expose the username and password credentials as plain text and could present a potential security risk.\n:::\n\n```r\ntoken <- auth_user(\n username = Sys.getenv(\"ARCGIS_USER\"),\n password = Sys.getenv(\"ARCGIS_PASSWORD\")\n host = arc_host(),\n expiration = 60\n)\nset_arc_token(token)\n```\n\n## Using `{arcgisbinding}`\n\nIf you are a user of ArcGIS Pro and have **arcgisbinding** installed, you can use `auth_binding()` to utilize the tokens that result from `arc.check_portal()`. `auth_binding()` has the benefit of being non-interactive _and_ authorizes you as a user. You can use `auth_binding()` for non-interactive work that creates or modifies existing content.\n\n```r\ntoken <- auth_binding()\nset_arc_token(token)\n```\n\nThis method retrieves the token from the *active* portal in ArcGIS Pro. Make sure that you are logged into the intended portal and that it is set as active. If you switch which portal is active in ArcGIS Pro, you will need to restart your R session for the new portal to be recognized by `auth_binding()`.\n\n\n## Using an API Key \n\nIf you are using ArcGIS Platform or using the ArcGIS Places Service, you will need to authorize via API key. Create an API key via the following instructions: \n\n* Navigate to https://developers.arcgis.com/\n* Sign in \n* Navigate to your API keys at https://developers.arcgis.com/api-keys/\n* Click `+ New API Key` & fill out the modal form\n\nStore the API key in your `.Renviron` file. You can call `usethis::edit_r_environ()` to open the file for you. \n\n```bash\nARCGIS_API_KEY=your-secret-api-key\n```\n\nRestart your R session for the key to be found. Next, load the `{arcgisutils}` package:\n\n```r\nlibrary(arcgisutils)\nauth_key()\n```", | ||
"supporting": [], | ||
"filters": [ | ||
"rmarkdown/pagebreak.lua" | ||
], | ||
"includes": {}, | ||
"engineDependencies": {}, | ||
"preserve": {}, | ||
"postProcess": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters