|
9 | 9 | "source": [ |
10 | 10 | "# Authenticating a HyP3 Session with the SDK\n", |
11 | 11 | "\n", |
12 | | - "When initializing a HyP3 object with the HyP3 SDK, you have three options:\n", |
| 12 | + "To access most HyP3 functions, you must authenticate using\n", |
| 13 | + "[Earthdata Login (EDL)](https://urs.earthdata.nasa.gov/) credentials.\n", |
| 14 | + "\n", |
| 15 | + "When initializing a HyP3 object with the HyP3 SDK, you have three authentication options:\n", |
13 | 16 | "1. Input your EDL username and password\n", |
14 | 17 | "2. Input your EDL Bearer Token\n", |
15 | 18 | "3. Store your credentials locally in a .netrc file in your home directory\n", |
16 | 19 | "\n", |
17 | | - "This tutorial will walk you through each of these authentication methods. If you have not created an Earthdata Login account yet, make sure to do so here: https://urs.earthdata.nasa.gov/users/new.\n", |
| 20 | + "This tutorial will walk you through each of these authentication methods. You can also refer to our\n", |
| 21 | + "[authentication documentation](https://hyp3-docs.asf.alaska.edu/using/authentication/) to learn more about HyP3 authentication.\n", |
| 22 | + "\n", |
| 23 | + "If you have not created an Earthdata Login account yet, you can do so here:\n", |
| 24 | + "[https://urs.earthdata.nasa.gov/users/new](https://urs.earthdata.nasa.gov/users/new)" |
| 25 | + ] |
| 26 | + }, |
| 27 | + { |
| 28 | + "cell_type": "markdown", |
| 29 | + "id": "9a6d6beb7a378045", |
| 30 | + "metadata": { |
| 31 | + "collapsed": false |
| 32 | + }, |
| 33 | + "source": [ |
| 34 | + "## Installing hyp3-sdk\n", |
| 35 | + "\n", |
| 36 | + "Before working through this notebook, make sure you have the `hyp3-sdk` Python package installed locally and\n", |
| 37 | + "ensure the version is >=7.7.0.\n", |
18 | 38 | "\n", |
19 | | - "Likewise, before starting, make sure you have `hyp3-sdk` installed locally and ensure the version is >=7.7.0." |
| 39 | + "If `hyp3-sdk` is not installed, you can run the next code cell to pip install it.\n", |
| 40 | + "Refer to the [SDK Example notebook](https://github.com/ASFHyP3/hyp3-sdk/blob/main/docs/sdk_example.ipynb)\n", |
| 41 | + "for more information on installation options." |
20 | 42 | ] |
21 | 43 | }, |
22 | 44 | { |
|
32 | 54 | ] |
33 | 55 | }, |
34 | 56 | { |
35 | | - "cell_type": "code", |
36 | | - "execution_count": null, |
37 | | - "outputs": [], |
| 57 | + "cell_type": "markdown", |
38 | 58 | "source": [ |
39 | | - "import hyp3_sdk as sdk" |
| 59 | + "Import the `hyp3_sdk` module." |
40 | 60 | ], |
41 | 61 | "metadata": { |
42 | 62 | "collapsed": false |
43 | 63 | }, |
44 | | - "id": "a38df62d8552468b" |
| 64 | + "id": "eb39ae640277c6d3" |
| 65 | + }, |
| 66 | + { |
| 67 | + "cell_type": "code", |
| 68 | + "execution_count": null, |
| 69 | + "id": "a38df62d8552468b", |
| 70 | + "metadata": { |
| 71 | + "collapsed": false |
| 72 | + }, |
| 73 | + "outputs": [], |
| 74 | + "source": [ |
| 75 | + "import hyp3_sdk as sdk" |
| 76 | + ] |
45 | 77 | }, |
46 | 78 | { |
47 | 79 | "cell_type": "markdown", |
|
50 | 82 | "collapsed": false |
51 | 83 | }, |
52 | 84 | "source": [ |
53 | | - "## Using your username and password\n", |
54 | | - "This option requires minimal amount of set up. All you need is to know your EDL username and password. You can either prompt for a username and password by passing `password` in as `prompt`:" |
| 85 | + "## Using your EDL Username and Password\n", |
| 86 | + "This option requires minimal set up. All you need is to know your\n", |
| 87 | + "[EDL username and password](https://hyp3-docs.asf.alaska.edu/using/authentication/#username-and-password). \n", |
| 88 | + "\n", |
| 89 | + "You can either prompt for a username and password by passing `password` in as `prompt`:" |
55 | 90 | ] |
56 | 91 | }, |
57 | 92 | { |
|
63 | 98 | }, |
64 | 99 | "outputs": [], |
65 | 100 | "source": [ |
66 | | - "HyP3 = sdk.HyP3(prompt='password')" |
| 101 | + "hyp3 = sdk.HyP3(prompt='password')" |
67 | 102 | ] |
68 | 103 | }, |
69 | 104 | { |
|
73 | 108 | "collapsed": false |
74 | 109 | }, |
75 | 110 | "source": [ |
76 | | - "Or pass them directly:" |
| 111 | + "or pass them directly:" |
77 | 112 | ] |
78 | 113 | }, |
79 | 114 | { |
|
88 | 123 | "username = 'myusername'\n", |
89 | 124 | "password = 'mypassword'\n", |
90 | 125 | "\n", |
91 | | - "HyP3 = sdk.HyP3(username=username, password=password)" |
| 126 | + "hyp3 = sdk.HyP3(username=username, password=password)" |
92 | 127 | ] |
93 | 128 | }, |
94 | 129 | { |
|
98 | 133 | "collapsed": false |
99 | 134 | }, |
100 | 135 | "source": [ |
101 | | - "## Using your EDL Bearer Token\n", |
102 | | - "Alternatively, you can authenticate your HyP3 object using your EDL token. Follow this documentation to create one: https://urs.earthdata.nasa.gov/documentation/for_users/user_token.\n", |
| 136 | + "## Using an EDL Bearer Token\n", |
| 137 | + "Alternatively, you can authenticate your HyP3 object using an EDL token. Follow this documentation to create one: [https://urs.earthdata.nasa.gov/documentation/for_users/user_token](https://urs.earthdata.nasa.gov/documentation/for_users/user_token)\n", |
103 | 138 | "\n", |
104 | | - "Once that token is set up, prompt for an EDL token:" |
| 139 | + "Once you have an EDL token, you can prompt for it by passing `token` in as `prompt`:" |
105 | 140 | ] |
106 | 141 | }, |
107 | 142 | { |
108 | 143 | "cell_type": "code", |
109 | 144 | "execution_count": null, |
110 | | - "outputs": [], |
111 | | - "source": [ |
112 | | - "HyP3 = sdk.HyP3(prompt='token')" |
113 | | - ], |
| 145 | + "id": "7805f87763471220", |
114 | 146 | "metadata": { |
115 | 147 | "collapsed": false |
116 | 148 | }, |
117 | | - "id": "7805f87763471220" |
| 149 | + "outputs": [], |
| 150 | + "source": [ |
| 151 | + "hyp3 = sdk.HyP3(prompt='token')" |
| 152 | + ] |
118 | 153 | }, |
119 | 154 | { |
120 | 155 | "cell_type": "markdown", |
121 | | - "source": [ |
122 | | - "Or pass it directly:" |
123 | | - ], |
| 156 | + "id": "19f255f3f2c1a7c4", |
124 | 157 | "metadata": { |
125 | 158 | "collapsed": false |
126 | 159 | }, |
127 | | - "id": "19f255f3f2c1a7c4" |
| 160 | + "source": [ |
| 161 | + "or pass it directly:" |
| 162 | + ] |
128 | 163 | }, |
129 | 164 | { |
130 | 165 | "cell_type": "code", |
|
136 | 171 | "outputs": [], |
137 | 172 | "source": [ |
138 | 173 | "token = 'mytoken'\n", |
139 | | - "HyP3 = sdk.HyP3(token=token)" |
| 174 | + "hyp3 = sdk.HyP3(token=token)" |
140 | 175 | ] |
141 | 176 | }, |
142 | 177 | { |
|
146 | 181 | "collapsed": false |
147 | 182 | }, |
148 | 183 | "source": [ |
149 | | - "## Using a local .netrc file\n", |
150 | | - "This option take a bit more effort to set up but saves time in the long run. You will create a .netrc file in your local home directory. \n", |
151 | | - "\n", |
152 | | - "You can do this by running the following commands, replacing `USER` and `PASSWORD` with your EDL username and password:" |
| 184 | + "## Using a Local .netrc File\n", |
| 185 | + "This option takes a bit more effort to set up, but saves time in the long run.\n", |
| 186 | + "By adding your credentials to the .netrc file saved in your local home directory, they can be pulled automatically\n", |
| 187 | + "when initializing the HyP3 object with the HyP3 SDK." |
153 | 188 | ] |
154 | 189 | }, |
| 190 | + { |
| 191 | + "cell_type": "markdown", |
| 192 | + "source": [ |
| 193 | + "You can add your credentials to a .netrc file programmatically.\n", |
| 194 | + "This approach first looks for an existing .netrc file and appends the credentials to it.\n", |
| 195 | + "If you don't already have a .netrc file, it will add one to your local home directory.\n", |
| 196 | + "\n", |
| 197 | + "Run the code cell below, replacing `USER` and `PASSWORD` with your EDL username and password:" |
| 198 | + ], |
| 199 | + "metadata": { |
| 200 | + "collapsed": false |
| 201 | + }, |
| 202 | + "id": "2b778c7c7c48074e" |
| 203 | + }, |
155 | 204 | { |
156 | 205 | "cell_type": "code", |
157 | 206 | "execution_count": null, |
|
173 | 222 | "collapsed": false |
174 | 223 | }, |
175 | 224 | "source": [ |
176 | | - "Now, when you initialize the HyP3 object, your credentials will be pulled from the .netrc file:" |
| 225 | + "Once the .netrc includes your credentials, you can initialize the HyP3 object without passing any arguments:" |
177 | 226 | ] |
178 | 227 | }, |
179 | 228 | { |
|
185 | 234 | }, |
186 | 235 | "outputs": [], |
187 | 236 | "source": [ |
188 | | - "HyP3 = sdk.HyP3()" |
| 237 | + "hyp3 = sdk.HyP3()" |
189 | 238 | ] |
190 | 239 | } |
191 | 240 | ], |
192 | 241 | "metadata": { |
193 | 242 | "kernelspec": { |
194 | | - "display_name": "Python 3", |
| 243 | + "display_name": "Python 3 (ipykernel)", |
195 | 244 | "language": "python", |
196 | 245 | "name": "python3" |
197 | 246 | }, |
198 | 247 | "language_info": { |
199 | 248 | "codemirror_mode": { |
200 | 249 | "name": "ipython", |
201 | | - "version": 2 |
| 250 | + "version": 3 |
202 | 251 | }, |
203 | 252 | "file_extension": ".py", |
204 | 253 | "mimetype": "text/x-python", |
205 | 254 | "name": "python", |
206 | 255 | "nbconvert_exporter": "python", |
207 | | - "pygments_lexer": "ipython2", |
208 | | - "version": "2.7.6" |
| 256 | + "pygments_lexer": "ipython3", |
| 257 | + "version": "3.11.13" |
209 | 258 | } |
210 | 259 | }, |
211 | 260 | "nbformat": 4, |
|
0 commit comments