Tuesday, November 3, 2015

GitHub Auth Basics | Using Sinatra (RubyGem) | "Persistent" Authentication

Hi Dev Fam,

This is actually part 3 of executing the GitHub Basic Authentication tutorial. Find part 1 and part 2 that I did here:
http://g2coding.blogspot.com/2015/10/github-auth-basics-using-sinatra.html
http://g2coding.blogspot.com/2015/10/github-auth-basics-using-sinatra_20.html

Implementing "Persistent" Authentication

We add the files "advanced_server.rb" and "advanced.erb" (inside "views" folder). Let's make sure no other code is running this Sinatra server by simply opening browser and accessing port: 4567.


Now, let's run the code. Again, I'm using Windows OS. So, I'll open my command prompt, go to my Ruby project folder and run:
C:\Users\[username]\RubyProjects\github-auth> ruby advanced_server.rb

This is how the home page should display in browser.


Oops, we got an error. The problem relates to the advanced.erb file when accessing a "null" email variable. We'll make the update to the code as similar to the basic.erb (by adding code '!email.nil? &&')


Now, let's run again and see if we have implemented the persistent authentication (stored within our session object).


Victory! Yes, it works! Congratulations, you did it!

My Code

My code is exactly the same as in the GitHub tutorial for the "advanced_server.rb" file. However, I have a slight modification to the "advanced.erb" file. Here's how my code looks in the view.



What's Next?

Try using this authentication from an organization account instead of as a user.
https://developer.github.com/guides/managing-deploy-keys/

No comments:

Post a Comment