---
title: "Logging in"
output: github_document
vignette: |
  %\VignetteIndexEntry{Logging in}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

## Signing up

Visit [https://cloud.tiledb.com](https://cloud.tiledb.com).

## Username+password login

Once you've set up your credentials at [https://cloud.tiledb.com](https://cloud.tiledb.com), and
once you've installed `TileDB-Cloud-R` (see [Setup](Setup.md)), you can log in from R CLI or
notebook as follows:

```
# Login for TileDB-Cloud-R per se
tiledbcloud::login(username="your-username", password="your-password")
```

```
# Login for TileDB-R delegating to cloud -- e.g. when you use tiledb::tiledb_array() with a URI like
# "tiledb://namespace-goes-here/arrayname-goes-here" in place of local-disk array storage.
config <- tiledb::tiledb_config()
config["rest.username"] <- "your-username"
config["rest.password"] <- "your-password"
ctx <- tiledb::tiledb_ctx(config)
```

## Token login

Visit [https://cloud.tiledb.com/settings/tokens](https://cloud.tiledb.com/settings/tokens) to create an
API token. Then you can do

```
tiledbcloud::login(api_key="[redacted]")
```

and

```
config <- tiledb::tiledb_config()
config["rest.token"] <- "[redacted]"
ctx <- tiledb::tiledb_ctx(config)
```

## Environment variables

Instead of using explicit `login` functions, you can set the following in your environment:

```
export TILEDB_REST_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNTVkYTc2YTMtOTVkNy00Njk5LThlN2EtNjFjZDRjNGZkZWY5IiwiU2VlZCI6NzM1MTI0MDcwOTk1ODcwMywiZXhwIjoxNjQxMDk5NTk5LCJpYXQiOjE2MzcxOTI0OTMsIm5iZiI6MTYzNzE5MjQ5Mywic3ViIjoiam9obmtlcmwifQ.el_L3L4hW7zS3NC3c12nO2-adNJG7IC77kitPH2AU60
export TILEDB_REST_USERNAME="your-username"
export TILEDB_REST_PASSWORD="your-password"
```

## Cached login

You can also put the same information in a `~/.tiledb/cloud.json` file:

```
{
    "api_key": {},
    "host": "https://api.dev.tiledb.io/v1",
    "username": "your-username",
    "password": "your-password",
    "verify_ssl": true
}
```

or

```
{
    "api_key": {
        "X-TILEDB-REST-API-KEY": "[redacted]z"
    },
    "host": "https://api.tiledb.com/v1",
    "verify_ssl": true
}
```

If you use the optional `write_config=TRUE` argument for `tiledbcloud::login`
then `~/.tiledb/cloud.json` will be written for you:

```
tiledbcloud::login(username="your-username", password="your-password", write_config=TRUE)
```

## Showing user profile

```
> str(tiledbcloud::user_profile())
$ id                              : chr "55da76a3-95d7-4699-8e7a-61cd4c4fdef9"
$ allowed_actions                 : chr [1:17] "delete" "edit" "write" "read" ...
$ name                            : chr "Sample User"
$ email                           : chr "sample.user@company.com"
$ is_valid_email                  : logi TRUE
$ stripe_connect                  : logi FALSE
$ last_activity_date              : chr "0001-01-01T00:00:00Z"
$ username                        : chr "sampleuser"
$ organizations                   :'data.frame': 2 obs. of  8 variables:
 ..$ user_id          : chr [1:2] "55da76a3-95d7-4699-8e7a-61cd4c4fdef9" "55da76a3-95d7-4699-8e7a-61cd4c4fdef9"
 ..$ organization_id  : chr [1:2] "6f568a58-717c-466a-a77d-30293eda5338" "96a37768-aae4-46f8-a9a1-a4fe9daa8158"
 ..$ allowed_actions  :List of 2
 .. ..$ : chr [1:5] "read" "read_array_logs" "read_array_info" "read_array_schema" ...
 .. ..$ : chr [1:17] "delete" "edit" "write" "read" ...
 ..$ role             : chr [1:2] "read_only" "owner"
 ..$ username         : chr [1:2] "sampleuser" "sampleuser"
 ..$ organization_name: chr [1:2] "public" "SampleOrganization"
 ..$ created_at       : chr [1:2] "2021-08-25T16:43:03Z" "2021-09-23T20:33:20Z"
 ..$ updated_at       : chr [1:2] "2021-08-26T16:21:14Z" "2021-09-23T20:33:20Z"
$ SSO                             : list()
$ timezone                        : chr "Asia/Istanbul"
$ company                         : chr "TileDB"
$ enabled_features                : chr [1:3] "notebooks" "generic_udfs" "notebook_sharing"
$ unpaid_subscription             : logi FALSE
$ default_s3_path                 : chr "s3://tiledb-sampleuser"
$ default_s3_path_credentials_name: chr "my-sandbox-creds"
$ default_s3_path_credentials_uuid: chr "f408eea2-aa9e-43e3-ab8f-a20358704c9c"
$ default_namespace_charged       : chr "sampleuser"
...
```
