Skip to content

Instantly share code, notes, and snippets.

@deadprogram
Last active April 10, 2026 21:31
Show Gist options
  • Select an option

  • Save deadprogram/5946244 to your computer and use it in GitHub Desktop.

Select an option

Save deadprogram/5946244 to your computer and use it in GitHub Desktop.
AT&T Developer Program - Example OAuth2 Ruby Client

Connecting To An AT&T Developer Program Service - The Basics

Getting Ready

  • Determine Where Your App Is Deployed
  • Register your application with APIMatrix
  • Obtain a client_id and client_secret for your app from APIMatrix

Making The Call

  • Request authorization code on the User's behalf from AT&T OAuth server
  • AT&T OAuth Server redirects back to your app with OAuth code
  • Use returned oauth code to request OAuth access token
  • Use OAuth access token to call API

Authorization

Your app will need to be given permission by each user in order to access their personal data. Here is how it works:

  • The app will navigate to the “Consent Request” page automatically, whenever the app needs to obtain authorization to access user data
  • User enters their username/password then click on "Allow" button
  • Now the application is authorized to call APIs on the user's behalf

Profile API

The Profile API allows you to return the user profile data for the current user. The user will need to give permission to the application that wants to retrieve this data, and the application will only be able to get the profile data for the user’s own account.

How To Run The Sample Code

bundle install
ATT_CLIENT_ID=<your client ID here> ATT_CLIENT_SECRET=<your secret here> ATT_AUTH_SERVER=<auth server> ruby helloapp.rb
require File.expand_path("helloapp", File.dirname(__FILE__))
run Sinatra::Application
source :rubygems
gem 'rack', "~> 1.3.6"
gem 'sinatra'
gem 'json'
gem 'oauth2'
require 'rubygems'
require 'sinatra'
require 'oauth2'
require 'json'
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
def client
OAuth2::Client.new((ENV['ATT_CLIENT_ID']||'testing'),
(ENV['ATT_CLIENT_SECRET']||'testing'),
:site => ENV['ATT_AUTH_SERVER'],
:authorize_url => "#{ENV['ATT_AUTH_SERVER']}/oauth/authorize",
:token_url => "#{ENV['ATT_AUTH_SERVER']}/oauth/token")
end
get "/" do
erb :index
end
get '/auth' do
authorization_url = client.auth_code.authorize_url(:redirect_uri => redirect_uri, :response_type => "code", :scope => "profile")
puts "Redirecting to URL: #{authorization_url.inspect}"
redirect authorization_url
end
get '/auth/callback' do
begin
access_token = client.auth_code.get_token(params[:code], :redirect_uri => redirect_uri)
api_url = "/me.json"
me = JSON.parse(access_token.get(api_url).body)
erb "<p>Your data:\n#{me.inspect}</p>"
rescue OAuth2::Error => e
erb %(<p>Wassup #{$!}</p><p><a href="/auth">Retry</a></p>)
end
end
get '/auth/failure' do
erb "<h1>Authentication Failed:</h1><h3>message:<h3> <pre>#{params}</pre>"
end
def redirect_uri(path = '/auth/callback', query = nil)
uri = URI.parse(request.url)
uri.path = path
uri.query = query
uri.to_s
end
__END__
@@ index
<form action="/auth">
<input type="submit" value="Profile" />
<form>
@@ layout
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AT&T Developer Program - Example App</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Le styles -->
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" rel="stylesheet">
<style>
body {
padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
}
</style>
<link href="http://twitter.github.com/bootstrap/assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
</a>
<a class="brand" href="/">AT&T Developer Program - Example App</a>
</div>
</div>
</div>
<div class="container">
<%= yield %>
</div> <!-- /container -->
</body>
</html>
@wyattverdrell173-blip666
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment