Sign in
Authorize
Logout
Session management is still on you
gitter.im
medium.com
dev.to
click
in a nutshell
made easy with
require "twitter_auth"
require "kemal"
require "uuid"
consumer_key = ENV["TWITTER_CONSUMER_KEY"]
consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
callback_url = ENV["TWITTER_CALLBACK_URL"]
callback_path = URI.parse(callback_url).path
auth_client = TwitterAPI.new(
consumer_key, consumer_secret, callback_url)
Users = Hash(String, TwitterAPI::TokenPair).new
Tokens = Set(String).new
require "twitter_auth"
require "kemal"
require "uuid"
consumer_key = ENV["TWITTER_CONSUMER_KEY"]
consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
callback_url = ENV["TWITTER_CALLBACK_URL"]
callback_path = URI.parse(callback_url).path
auth_client = TwitterAPI.new(
consumer_key, consumer_secret, callback_url)
Users = Hash(String, TwitterAPI::TokenPair).new
Tokens = Set(String).new
require "twitter_auth"
require "kemal"
require "uuid"
consumer_key = ENV["TWITTER_CONSUMER_KEY"]
consumer_secret = ENV["TWITTER_CONSUMER_SECRET"]
callback_url = ENV["TWITTER_CALLBACK_URL"]
callback_path = URI.parse(callback_url).path
auth_client = TwitterAPI.new(
consumer_key, consumer_secret, callback_url)
Users = Hash(String, TwitterAPI::TokenPair).new
Tokens = Set(String).new
get "/authenticate" do |ctx|
request_token = auth_client.get_token.oauth_token
Tokens.add request_token
ctx.redirect TwitterAPI.authenticate_url(request_token)
end
click
get "/authenticate" do |ctx|
request_token = auth_client.get_token.oauth_token
Tokens.add request_token
ctx.redirect TwitterAPI.authenticate_url(request_token)
end
get "/authenticate" do |ctx|
request_token = auth_client.get_token.oauth_token
Tokens.add request_token
ctx.redirect TwitterAPI.authenticate_url(request_token)
end
get "/authenticate" do |ctx|
request_token = auth_client.get_token.oauth_token
Tokens.add request_token
ctx.redirect TwitterAPI.authenticate_url(request_token)
end
get callback_path do |ctx|
token = ctx.params.query["oauth_token"]
halt(ctx, status_code: 400) unless Tokens.includes? token
Tokens.delete(token)
verifier = ctx.params.query["oauth_verifier"]
token, secret = auth_client.upgrade_token(token, verifier)
app_token = UUID.random.to_s
Users[app_token] = TwitterAPI::TokenPair.new(token, secret)
ctx.response.headers.add "Location", "/?token=#{app_token}"
ctx.response.status_code = 302
end
click
my-usr
*******
get callback_path do |ctx|
token = ctx.params.query["oauth_token"]
halt(ctx, status_code: 400) unless Tokens.includes? token
Tokens.delete(token)
verifier = ctx.params.query["oauth_verifier"]
token, secret = auth_client.upgrade_token(token, verifier)
app_token = UUID.random.to_s
Users[app_token] = TwitterAPI::TokenPair.new(token, secret)
ctx.response.headers.add "Location", "/?token=#{app_token}"
ctx.response.status_code = 302
end
my-usr
*******
get callback_path do |ctx|
token = ctx.params.query["oauth_token"]
halt(ctx, status_code: 400) unless Tokens.includes? token
Tokens.delete(token)
verifier = ctx.params.query["oauth_verifier"]
token, secret = auth_client.upgrade_token(token, verifier)
app_token = UUID.random.to_s
Users[app_token] = TwitterAPI::TokenPair.new(token, secret)
ctx.response.headers.add "Location", "/?token=#{app_token}"
ctx.response.status_code = 302
end
my-usr
*******
get callback_path do |ctx|
token = ctx.params.query["oauth_token"]
halt(ctx, status_code: 400) unless Tokens.includes? token
Tokens.delete(token)
verifier = ctx.params.query["oauth_verifier"]
token, secret = auth_client.upgrade_token(token, verifier)
app_token = UUID.random.to_s
Users[app_token] = TwitterAPI::TokenPair.new(token, secret)
ctx.response.headers.add "Location", "/?token=#{app_token}"
ctx.response.status_code = 302
end
my-usr
*******
get callback_path do |ctx|
token = ctx.params.query["oauth_token"]
halt(ctx, status_code: 400) unless Tokens.includes? token
Tokens.delete(token)
verifier = ctx.params.query["oauth_verifier"]
token, secret = auth_client.upgrade_token(token, verifier)
app_token = UUID.random.to_s
Users[app_token] = TwitterAPI::TokenPair.new(token, secret)
ctx.response.headers.add "Location", "/?token=#{app_token}"
ctx.response.status_code = 302
end
my-usr
*******
get callback_path do |ctx|
token = ctx.params.query["oauth_token"]
halt(ctx, status_code: 400) unless Tokens.includes? token
Tokens.delete(token)
verifier = ctx.params.query["oauth_verifier"]
token, secret = auth_client.upgrade_token(token, verifier)
app_token = UUID.random.to_s
Users[app_token] = TwitterAPI::TokenPair.new(token, secret)
ctx.response.headers.add "Location", "/?token=#{app_token}"
ctx.response.status_code = 302
end
my-usr
*******
get "/verify" do |ctx|
_, twitter_token = credentials(ctx)
halt(ctx, status_code: 401) if twitter_token.nil?
ctx.response.content_type = "application/json"
auth_client.verify(twitter_token)
end
get "/verify" do |ctx|
_, twitter_token = credentials(ctx)
halt(ctx, status_code: 401) if twitter_token.nil?
ctx.response.content_type = "application/json"
auth_client.verify(twitter_token)
end
get "/verify" do |ctx|
_, twitter_token = credentials(ctx)
halt(ctx, status_code: 401) if twitter_token.nil?
ctx.response.content_type = "application/json"
auth_client.verify(twitter_token)
end
get "/logout" do |ctx|
app_token, twitter_token = credentials(ctx)
halt(ctx, status_code: 401) if twitter_token.nil?
auth_client.invalidate_token(twitter_token)
Users.delete(app_token)
ctx.redirect "/"
end
click
get "/logout" do |ctx|
app_token, twitter_token = credentials(ctx)
halt(ctx, status_code: 401) if twitter_token.nil?
auth_client.invalidate_token(twitter_token)
Users.delete(app_token)
ctx.redirect "/"
end
get "/logout" do |ctx|
app_token, twitter_token = credentials(ctx)
halt(ctx, status_code: 401) if twitter_token.nil?
auth_client.invalidate_token(twitter_token)
Users.delete(app_token)
ctx.redirect "/"
end
get "/logout" do |ctx|
app_token, twitter_token = credentials(ctx)
halt(ctx, status_code: 401) if twitter_token.nil?
auth_client.invalidate_token(twitter_token)
Users.delete(app_token)
ctx.redirect "/"
end
get "/logout" do |ctx|
app_token, twitter_token = credentials(ctx)
halt(ctx, status_code: 401) if twitter_token.nil?
auth_client.invalidate_token(twitter_token)
Users.delete(app_token)
ctx.redirect "/"
end
click
<body>
<div class="content" id="app">
<div v-if="loaded">
<div v-if="logged_in">
You are logged in as {{ username }}
<a href="#" v-on:click="logout">Logout</a>
</div>
<div v-else>
<a href="/authenticate"><img src="sign-in.png"></a>
</div>
</div>
<div v-else>Loading</div>
</div>
<script src="index.js"></script>
</body>
<body>
<div class="content" id="app">
<div v-if="loaded">
<div v-if="logged_in">
You are logged in as {{ username }}
<a href="#" v-on:click="logout">Logout</a>
</div>
<div v-else>
<a href="/authenticate"><img src="sign-in.png"></a>
</div>
</div>
<div v-else>Loading</div>
</div>
<script src="index.js"></script>
</body>
<body>
<div class="content" id="app">
<div v-if="loaded">
<div v-if="logged_in">
You are logged in as {{ username }}
<a href="#" v-on:click="logout">Logout</a>
</div>
<div v-else>
<a href="/authenticate"><img src="sign-in.png"></a>
</div>
</div>
<div v-else>Loading</div>
</div>
<script src="index.js"></script>
</body>
var app = new Vue({
el: '#app',
data: {
loaded: false,
logged_in: false,
username: null
},
// ...
})
// page initialisation
var urlParams = new URLSearchParams(window.location.search)
token = urlParams.get("token")
if(token == null) {
this.logged_in = false
this.loaded = true
} else {
fetch('/verify', {headers: {token}})
.then(response => response.json())
.then(data => {
this.logged_in = true
this.username = data.name
this.loaded = true
})
}
// page initialisation
var urlParams = new URLSearchParams(window.location.search)
token = urlParams.get("token")
if(token == null) {
this.logged_in = false
this.loaded = true
} else {
fetch('/verify', {headers: {token}})
.then(response => response.json())
.then(data => {
this.logged_in = true
this.username = data.name
this.loaded = true
})
}
// page initialisation
var urlParams = new URLSearchParams(window.location.search)
token = urlParams.get("token")
if(token == null) {
this.logged_in = false
this.loaded = true
} else {
fetch('/verify', {headers: {token}})
.then(response => response.json())
.then(data => {
this.logged_in = true
this.username = data.name
this.loaded = true
})
}
// page initialisation
var urlParams = new URLSearchParams(window.location.search)
token = urlParams.get("token")
if(token == null) {
this.logged_in = false
this.loaded = true
} else {
fetch('/verify', {headers: {token}})
.then(response => response.json())
.then(data => {
this.logged_in = true
this.username = data.name
this.loaded = true
})
}
<body>
<div class="content" id="app">
<div v-if="loaded">
<div v-if="logged_in">
You are logged in as {{ username }}
<a href="#" v-on:click="logout">Logout</a>
</div>
fetch('/verify', {headers: {token}})
.then(response => response.json())
.then(data => {
this.logged_in = true
this.username = data.name
this.loaded = true
})
}