You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Note that a token must minimally have the **view** scope to be used with the Synapse Python Client.
10
10
* Include **Download** and **Modify** permissions if you are using the Synapse Python Client to follow any subsequent tutorials.
@@ -19,6 +19,7 @@ Use the [synapseclient.login][synapseclient.Synapse.login] function
19
19
```python
20
20
import synapseclient
21
21
syn = synapseclient.login(authToken="authtoken")
22
+
#returns Welcome, First Last!
22
23
```
23
24
24
25
### Command Line Client
@@ -37,43 +38,133 @@ Logged in as: username (1234567)
37
38
38
39
For writing code using the Synapse Python client that is easy to share with others, please do not include your credentials in the code. Instead, please use the `~/.synapseConfig` file to manage your credentials.
39
40
41
+
The Synapse Python Client supports multiple profiles within the `~/.synapseConfig` file, enabling users to manage credentials for multiple accounts. Each profile is defined in its own `[profile <profile_name>]` section. A default profile can still be defined using `[default]`.
42
+
40
43
When installing the Synapse Python client, the `~/.synapseConfig` is added to your home directory.
41
44
42
45
### Automatically modifying the `~/.synapseConfig` file with the Command line Client
43
46
You may modify the `~/.synapseConfig` file by utilizing the [command line client command and following the interactive prompts](./command_line_client.md#config):
44
47
48
+
#### Modifying the synapse config for multiple profiles
49
+
45
50
<!-- termynal -->
46
51
```
47
52
> synapse config
48
-
Synapse username (Optional):
53
+
54
+
Synapse username (Optional): $MY_USERNAME
55
+
56
+
Auth token: $MY_SYNAPSE_TOKEN
57
+
58
+
Configuration profile name (Optional, 'default' used if not specified): $MY_CONFIG_PROFILE
59
+
```
60
+
61
+
#### Adding or updating a specific profile passed in as a command line argument
62
+
<!-- termynal -->
63
+
```
64
+
> synapse --profile $MY_PROFILE_NAME config
65
+
66
+
Synapse username (Optional): $MY_USERNAME
49
67
50
68
Auth token: $MY_SYNAPSE_TOKEN
51
69
```
52
70
71
+
Note: If you encounter a PermissionError
72
+
(e.g., `[Errno 13] Permission denied: '/Users/username/.synapseConfig'`), it is likely that the user does not have write permissions to the `~/.synapseConfig` file.
73
+
To resolve this, ensure that you have the necessary permissions to modify this file.
74
+
You can change the permissions using the following command:
75
+
76
+
`chmod u+w ~/.synapseConfig`
77
+
78
+
53
79
### Manually modifying the `~/.synapseConfig` file
54
80
The following describes how to add your credentials to the `~/.synapseConfig` file without the use of the `synapse config` command.
55
81
56
-
Open the `~/.synapseConfig` file and find the following section:
82
+
Open the `~/.synapseConfig` file using your preferred text editing tool and find/insert the following section(s):
57
83
58
84
```
85
+
[default]
86
+
username = default_user
87
+
authtoken = default_auth_token
88
+
89
+
[profile user1]
90
+
username = user1
91
+
authtoken = user1_auth_token
92
+
93
+
[profile user2]
94
+
username = user2
95
+
authtoken = user2_auth_token
96
+
97
+
# This section is deprecated. It will be used if a `default` profile or a specific profile is not present in the config file
59
98
#[authentication]
60
-
#username = <username>
61
-
#authtoken = <authtoken>
99
+
#username = default_user
100
+
#authtoken = default_auth_token
62
101
```
63
102
64
-
To enable this section, uncomment it. You don't need to specify your username when using authtoken as a pair, but if you do, it will be used to verify your identity. A personal access token generated from your synapse.org Settings can be used as your .synapseConfig authtoken.
103
+
`username` is optional when using `authtoken`, but if provided, an additional check to verify the `authtoken` matches the `username` is performed.
104
+
105
+
The `authoken` is also know as a personal access token. It is generated from your [synapse.org Settings](https://help.synapse.org/docs/Managing-Your-Account.2055405596.html#ManagingYourAccount-PersonalAccessTokens)..
106
+
107
+
### Transitioning from One Profile to Multiple
108
+
109
+
If you're currently using a single profile (under the `[default]` or `[authentication]` section) and wish to start using multiple profiles,
110
+
simply add new sections for each profile with a unique profile name. For example, you can add a profile for user1 and user2 as shown below.
111
+
The Synapse Python client will allow you to choose which profile to use at login.
112
+
65
113
```
66
-
[authentication]
67
-
authtoken = <authtoken>
114
+
[default]
115
+
username = default_user
116
+
authtoken = default_auth_token
117
+
118
+
[profile user1]
119
+
username = user1
120
+
authtoken = user1_auth_token
121
+
122
+
[profile user2]
123
+
username = user2
124
+
authtoken = user2_auth_token
68
125
```
69
126
70
-
Now, you can login without specifying any arguments:
127
+
## Logging in with your ~/.synapseConfig file
128
+
129
+
**Note:** If no profile is specified the `default` section will be used. Additionally, to support backwards compatibility, `authentication` will continue to function. `authentication` will be used if no profile is used and `default` is not present in the configuration file.
130
+
131
+
### Logging in via python code
71
132
72
133
```python
73
134
import synapseclient
74
135
syn = synapseclient.login()
75
136
```
76
137
138
+
If you want to log in with a specific profile, simply pass the profile name as an argument to `login()`:
139
+
140
+
```python
141
+
import synapseclient
142
+
syn = synapseclient.login(profile="user1")
143
+
```
144
+
145
+
### Logging in via the command line
146
+
147
+
Logs in with the `default` profile, or the profile set in the `SYNAPSE_PROFILE` environment variable:
148
+
149
+
<!-- termynal -->
150
+
```
151
+
#For default login
152
+
> synapse login
153
+
154
+
returns Welcome, last first!
155
+
```
156
+
157
+
Logging in with the `profile_name` given:
158
+
159
+
<!-- termynal -->
160
+
```
161
+
#For profile login
162
+
163
+
> synapse --profile profile_name login
164
+
165
+
Welcome, last first! You are using the 'profile_name' profile.
166
+
```
167
+
77
168
## Use Environment Variable
78
169
79
170
Setting the `SYNAPSE_AUTH_TOKEN` environment variable will allow you to login to Synapse with a [Personal Access Token](https://help.synapse.org/docs/Managing-Your-Account.2055405596.html#ManagingYourAccount-PersonalAccessTokens)
@@ -86,21 +177,26 @@ In your shell, you can pass an environment variable to Python inline by defining
Once you are inside Python, you may simply login without passing any arguments:
187
+
Setting the `SYNAPSE_PROFILE` environment variable will allow you to log into Synapse using a specific authentication profile present in your `.synapseConfig` file. This allows you to have multiple profiles present in a single configuration file that you may swap between. Alternatively, you may use the `profile` parameter in Python, or the `--profile` command line flag for all commands like `synapse --profile <profile_name> COMMAND`.
188
+
189
+
Once you are inside Python, you may simply login without passing any arguments, or pass a profile argument to access a specific profile:
97
190
98
191
```python
99
192
import synapseclient
100
193
syn = synapseclient.login()
194
+
195
+
import synapseclient
196
+
syn = synapseclient.login(profile="user1")
101
197
```
102
198
103
-
To use the environment variable with the command line client, simply substitute `python` for the `synapse` command
199
+
To use the environment variable with the command line client, simply substitute `python` for the `synapse` command:
104
200
105
201
```bash
106
202
SYNAPSE_AUTH_TOKEN='<my_personal_access_token>' synapse get syn123
0 commit comments