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
Copy file name to clipboardExpand all lines: content/guides/basics-of-authentication.md
+13-7Lines changed: 13 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,8 @@ In this section, we're going to focus on the basics of authentication. Specifica
11
11
we're going to create a Ruby server (using [Sinatra][Sinatra]) that implements
12
12
the [web flow][webflow] of an application in several different ways.
13
13
14
+
Note: you can download the complete source code for this project [from the platform-samples repo](https://github.com/github/platform-samples/tree/master/api/ruby/basics-of-authentication).
15
+
14
16
## Registering your app
15
17
16
18
First, you'll need to [register your
@@ -25,7 +27,7 @@ up your application. It's the callback URL that GitHub returns the user to after
25
27
successful authentication.
26
28
27
29
Since we're running a regular Sinatra server, the location of the local instance
28
-
is set to `http://localhost/:4567`. Let's fill in the callback URL as `http://localhost/:4567/callback`.
30
+
is set to `http://localhost:4567`. Let's fill in the callback URL as `http://localhost:4567/callback`.
29
31
30
32
## Accepting user authorization
31
33
@@ -62,16 +64,16 @@ Next, in _views/index.erb_, paste this content:
62
64
63
65
Obviously, you'll want to change `<your_client_id>` to match your actual Client ID.
64
66
65
-
Navigate your browser to `http://localhost/:4567`. After clicking on the link, you
67
+
Navigate your browser to `http://localhost:4567`. After clicking on the link, you
66
68
should be taken to GitHub, and presented with a dialog that looks something like this:
67
69

68
70
69
71
If you trust yourself, click **Authorize App**. Wuh-oh! Sinatra spits out a
70
72
`404` error. What gives?!
71
73
72
74
Well, remember when we specified a Callback URL to be `callback`? We didn't provide
73
-
a route for it, so GitHub doesn't know where to drop the user after they authorize the app.
74
-
Let's fix that now!
75
+
a route for it, so GitHub doesn't know where to drop the user after they authorize
76
+
the app. Let's fix that now!
75
77
76
78
### Providing a callback
77
79
@@ -113,7 +115,7 @@ We can do whatever we want with our results. In this case, we'll just dump them
113
115
114
116
It'd be a pretty bad model if we required users to log into the app every single
115
117
time they needed to access the web page. For example, try navigating directly to
116
-
`http://localhost/:4567/basic`. You'll get an error.
118
+
`http://localhost:4567/basic`. You'll get an error.
117
119
118
120
What if we could circumvent the entire
119
121
"click here" process, and just _remember_ that, as log as the user's logged into
@@ -217,7 +219,7 @@ Next, create a file in _views_ called _advanced.erb_, and paste this markup into
217
219
218
220
From the command line, call `rackup -p 4567`, which starts up your
219
221
Rack server on port `4567`--the same port we used when we had a simple Sinatra app.
220
-
When you navigate to `http://localhost/:4567`, the app calls `authenticate!`--another
222
+
When you navigate to `http://localhost:4567`, the app calls `authenticate!`--another
221
223
internal `sinatra-auth-github` method--which redirects you to `/callback`. `/callback`
222
224
then sends us back to `/`, and since we've been authenticated, renders _advanced.erb_.
223
225
@@ -228,6 +230,9 @@ the same callback URL, we've got to do a little bit of wonkiness to make it work
228
230
Also, if we had never authorized this Rack application to access our GitHub data,
229
231
we would've seen the same confirmation dialog from earlier pop-up and warn us.
230
232
233
+
If you'd like, you can play around with [yet another Sinatra-GitHub auth example][sinatra auth github test]
Copy file name to clipboardExpand all lines: content/guides/rendering-data-as-graphs.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,8 @@ be using Octokit, a Ruby library designed to interact with the GitHub API.
14
14
We're going to jump right in and assume you've already read the ["Basics of Authentication"][basics-of-authentication]
15
15
guide.
16
16
17
+
Note: you can download the complete source code for this project [from the platform-samples repo](https://github.com/github/platform-samples/tree/master/api/ruby/rendering-data-as-graphs).
18
+
17
19
Go ahead and register an application through GitHub. Set the main URL and callback
18
20
URL to `http://localhost:4567/`. As before, we're going to be implementing a Rack middleware
0 commit comments