Skip to content

Commit e86345a

Browse files
committed
First commit
0 parents  commit e86345a

File tree

147 files changed

+10787
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+10787
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Ruby and Rails Example Applications powered by WorkOS
2+
3+
Example applications demonstrating to use the [WorkOS Ruby SDK](https://github.com/workos-inc/workos-ruby) for SSO, Directory Sync, Admin Portal and Magic Link.
4+
5+
## For more information, please see the following guides:
6+
7+
* [Single Sign-On](https://workos.com/docs/sso/guide)
8+
* [Directory Sync](https://workos.com/docs/directory-sync/guide)
9+
* [Admin Portal](https://workos.com/docs/admin-portal/guide)
10+
* [Magic Link](https://workos.com/docs/magic-link/guide)
11+
* [API Reference](https://workos.com/docs/reference)
12+
13+
## Need help?
14+
15+
If you get stuck and aren't able to resolve the issue by reading our [WorkOS Ruby SDK documentation](https://docs.workos.com/sdk/ruby) or [API reference](https://workos.com/docs/reference), you can reach out to us at [email protected] and we'll lend a hand!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
WORKOS_API_KEY=<Replace with your key>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.7.1

ruby-directory-sync-example/Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
source 'https://rubygems.org'
4+
5+
gem 'dotenv'
6+
gem 'sinatra'
7+
gem 'workos'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
dotenv (2.7.6)
5+
mustermann (1.1.1)
6+
ruby2_keywords (~> 0.0.1)
7+
rack (2.2.3)
8+
rack-protection (2.1.0)
9+
rack
10+
ruby2_keywords (0.0.5)
11+
sinatra (2.1.0)
12+
mustermann (~> 1.0)
13+
rack (~> 2.2)
14+
rack-protection (= 2.1.0)
15+
tilt (~> 2.0)
16+
sorbet-runtime (0.5.9293)
17+
tilt (2.0.10)
18+
workos (1.6.0)
19+
sorbet-runtime (~> 0.5)
20+
21+
PLATFORMS
22+
ruby
23+
24+
DEPENDENCIES
25+
dotenv
26+
sinatra
27+
workos
28+
29+
BUNDLED WITH
30+
2.1.4

ruby-directory-sync-example/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 WorkOS
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

ruby-directory-sync-example/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# ruby-directory-sync-example
2+
3+
An example Sinatra application demonstrating how Directory Sync works with WorkOS and Ruby.
4+
5+
## Clone and Install
6+
7+
1. Clone the main repo:
8+
9+
```sh
10+
git clone https://github.com/workos-inc/ruby-example-applications.git
11+
```
12+
13+
2. Navigate to the Ruby Directory Sync app within the main repo and install dependencies:
14+
15+
```sh
16+
cd ruby-example-applications/ruby-directory-sync-example && bundle install
17+
```
18+
19+
## Configure your environment
20+
21+
1. Grab your [API Key](https://dashboard.workos.com/api-keys).
22+
2. Run `cp .env.example .env` and add your API key. The `workos` gem will read your API key from the ENV variable `WORKOS_API_KEY`. You may also set the API key yourself by adding `WorkOS.key = $YOUR_API_KEY` to `app.rb`.
23+
24+
## Run the app
25+
26+
```sh
27+
ruby app.rb
28+
```
29+
30+
Head to `http://localhost:4567`!
31+
32+
For more information, see the [WorkOS Ruby SDK documentation](https://docs.workos.com/sdk/ruby).

ruby-directory-sync-example/app.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
require 'dotenv/load'
4+
require 'sinatra'
5+
require 'workos'
6+
require 'json'
7+
8+
# Pull API key from ENV variable
9+
WorkOS.key = ENV['WORKOS_API_KEY']
10+
11+
get '/' do
12+
@directories = WorkOS::DirectorySync.list_directories
13+
14+
erb :index
15+
end
16+
17+
get '/directories/:id' do
18+
@groups = WorkOS::DirectorySync.list_groups(directory: params[:id])
19+
@users = WorkOS::DirectorySync.list_users(directory: params[:id])
20+
21+
erb :directory
22+
end
23+
24+
get '/users/:id' do
25+
@user = WorkOS::DirectorySync.get_user(params[:id])
26+
@user_groups = WorkOS::DirectorySync.list_groups(user: params[:id])
27+
28+
erb :user
29+
end
30+
31+
get '/groups/:id' do
32+
@group = WorkOS::DirectorySync.get_group(params[:id])
33+
@group_users = WorkOS::DirectorySync.list_users(group: params[:id])
34+
35+
erb :group
36+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<% if @users.any? %>
2+
<h2>Users</h2>
3+
4+
<ul>
5+
<% @users.each do |user| %>
6+
<li>
7+
<a href="/users/<%= user['id'] %>">
8+
<%= user['username'] %>
9+
</a>
10+
</li>
11+
<% end %>
12+
</ul>
13+
<% end %>
14+
15+
16+
<% if @groups.any? %>
17+
<h2>Groups</h2>
18+
19+
<ul>
20+
<% @groups.each do |group| %>
21+
<li>
22+
<a href="/groups/<%= group['id'] %>">
23+
<%= group['name'] %>
24+
</a>
25+
</li>
26+
<% end %>
27+
</ul>
28+
<% end %>

0 commit comments

Comments
 (0)