class: center, middle, inverse, title-slide # Personal Authentication Tokens ## The GitHub PAT ### Colin Gillespie (<a href="https://twitter.com/csgillespie">@csgillespie</a>) --- layout:true layout: true <div class="jr-header"> <img class="logo" src="assets/white_logo_full.png"/> <span class="social"><table><tr><td><img src="assets/twitter.gif"/></td><td> @jumping_uk</td></tr></table></span> </div> <div class="jr-footer"><span>© 2019 Jumping Rivers (jumpingrivers.com)</span><div>http://bit.ly/user2019-git</div></div> --- # Why? - When installing packages on travis, each user is given 5,000 free calls per hour - After that, you get a 403 error -- - travis.yml uses `devtools::install_github()` - __devtools__ looks an environment variable called `GITHUB_PAT` - if it doesn't exist, it uses a default (that gets easily overloaded) -- - Solution: Create the PAT! --- # Personal Access Tokens (PAT) * We'll obtain a PAT via the browser - possible to get via __usethis__ --- # DEMO: Personal Access Tokens (PAT) * Create a PAT with no permissions i.e. untick all the permissions boxes - https://github.com/settings/tokens - I typically call mine GITHUB_PAT * Copy the key * We want to store the key in our `.Renviron` file ```r ## Open the file usethis::edit_r_environ() ``` * Add the line ``` GITHUB_PAT=YOUR-PAT ``` * Restart R and run `Sys.getenv("GITHUB_PAT")` --- # TASK: Personal Access Tokens (PAT) * Create a PAT with no permissions i.e. untick all the permissions boxes - https://github.com/settings/tokens - I typically call mine GITHUB_PAT * Copy the key * We want to store the key in our `.Renviron` file ```r ## Open the file usethis::edit_r_environ() ``` * Add the line ``` GITHUB_PAT=YOUR-PAT ``` * Restart R and run `Sys.getenv("GITHUB_PAT")` <div class="countdown blink-colon noupdate-10" id="timer_5d2459fb" style="right:0;bottom:0;" data-warnwhen="0"> <code class="countdown-time"><span class="countdown-digits minutes">10</span><span class="countdown-digits colon">:</span><span class="countdown-digits seconds">00</span></code> </div> --- # DEMO: Now add it to GITHUB Run ```r travis::travis_browse() ``` to get to your travis page * More options -> settings -> Environment variables * NAME: `GITHUB_PAT` * VALUE: `Long string` * Click `Add` * Re-run your travis build * Line ~563 you should see `export GITHUB_PAT=[secure]` --- # TASK: Now add it to GITHUB Run ```r travis::travis_browse() ``` to get to your travis page * More options -> settings -> Environment variables * NAME: `GITHUB_PAT` * VALUE: `Long string` * Click `Add` * Re-run your travis build * Line ~563 you should see `export GITHUB_PAT=[secure]` * Bonus: Try and get travis to print out your secured variable - `Sys.getenv("GITHUB_PAT")` <div class="countdown blink-colon noupdate-15" id="timer_5d24586f" style="right:0;bottom:0;" data-warnwhen="0"> <code class="countdown-time"><span class="countdown-digits minutes">12</span><span class="countdown-digits colon">:</span><span class="countdown-digits seconds">00</span></code> </div>