-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b13fc02
commit f75129a
Showing
24 changed files
with
445 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name: authly | ||
version: 1.2.5 | ||
version: 1.2.6 | ||
authors: | ||
- Elias Perez <elias.perez@nytimes.com> | ||
crystal: '>=0.31.1' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# Spec file for testing the Grant class and its compliance with OAuth2 specifications | ||
require "./spec_helper" | ||
|
||
module Authly | ||
describe Grant do | ||
client_id = "1" | ||
client_secret = "secret" | ||
username = "username" | ||
password = "password" | ||
redirect_uri = "hhttps://www.example.com/callback" | ||
refresh_token = "test_refresh_token" | ||
authorization_code = Authly::Code.new(client_id, "read", redirect_uri, "", "", username).to_s | ||
|
||
it "creates an access token with valid client credentials grant" do | ||
grant = Grant.new("client_credentials", client_id: client_id, client_secret: client_secret) | ||
token = grant.token | ||
|
||
token.client_id.should eq client_id | ||
token.scope.should eq "" | ||
end | ||
|
||
it "creates an access token with valid password grant" do | ||
grant = Grant.new("password", | ||
client_id: client_id, | ||
client_secret: client_secret, | ||
username: username, | ||
password: password) | ||
|
||
token = grant.token | ||
|
||
token.client_id.should eq client_id | ||
token.scope.should eq "" | ||
end | ||
|
||
it "creates an access token with valid authorization code grant" do | ||
grant = Grant.new("authorization_code", | ||
client_id: client_id, | ||
client_secret: client_secret, | ||
redirect_uri: redirect_uri, | ||
code: authorization_code) | ||
|
||
token = grant.token | ||
|
||
token.client_id.should eq client_id | ||
token.scope.should eq "read" | ||
end | ||
|
||
it "creates an access token with valid refresh token grant" do | ||
authorization_code = Authly::Code.new(client_id, "read", redirect_uri, "", "", username).to_s | ||
|
||
grant = Grant.new("refresh_token", | ||
client_id: client_id, | ||
client_secret: client_secret, | ||
refresh_token: refresh_token, | ||
code: authorization_code) | ||
|
||
token = grant.token | ||
|
||
token.client_id.should eq client_id | ||
token.scope.should eq "" | ||
end | ||
|
||
it "raises error for unsupported grant type" do | ||
expect_raises(Error) { Grant.new("unsupported_grant_type", client_id: client_id, client_secret: client_secret) } | ||
end | ||
|
||
it "validates scope for access token" do | ||
grant = Grant.new("authorization_code", | ||
client_id: client_id, | ||
client_secret: client_secret, | ||
redirect_uri: redirect_uri, | ||
code: authorization_code) | ||
|
||
grant.code = Authly.jwt_encode({"scope" => "read"}) | ||
token = grant.token | ||
|
||
token.scope.should eq "read" | ||
end | ||
|
||
it "raises error for invalid scope" do | ||
scope = "pluto" | ||
invalid_scope = "mars" | ||
Authly.clients << Authly::Client.new("new_client", "secret", "https://www.example.com/callback", "2", scope) | ||
authorization_code = Authly::Code.new("2", invalid_scope, redirect_uri, "", "", username).to_s | ||
|
||
grant = Grant.new("authorization_code", | ||
client_id: "2", | ||
client_secret: client_secret, | ||
redirect_uri: redirect_uri, | ||
code: authorization_code) | ||
|
||
expect_raises(Error) { grant.token } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
secret_key = "4bce37fbb1542a68dddba2da22635beca9d814cb3424c461fcc8876904ad39c1" | ||
BASE_URI = "http://0.0.0.0:4000" | ||
STATE_STORE = Authly::InMemoryStateStore.new | ||
|
||
Authly.configure do |config| | ||
config.secret_key = secret_key | ||
config.public_key = secret_key | ||
config.state_store = STATE_STORE | ||
end | ||
|
||
Authly.clients << Authly::Client.new("example", "secret", "https://www.example.com/callback", "1") | ||
Authly.owners << Authly::Owner.new("username", "password") | ||
|
||
OAUTH_HANDLER = Authly::Handler.new |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
require "http/server" | ||
require "../src/authly" | ||
require "../../src/authly" | ||
require "./settings" | ||
|
||
server = HTTP::Server.new([ | ||
Authly::OAuthHandler.new, | ||
Authly::Handler.new, | ||
]) | ||
server.bind_tcp "0.0.0.0", 4000 | ||
puts "Listening on http://0.0.0.0:4000" | ||
|
||
server.listen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.