-
Notifications
You must be signed in to change notification settings - Fork 23
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
Showing
13 changed files
with
757 additions
and
190 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,43 +1,41 @@ | ||
require "../spec_helper" | ||
|
||
describe MultiAuth do | ||
context "facebook" do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("facebook", "/callback").authorize_uri | ||
uri.should eq("https://www.facebook.com/v2.9/dialog/oauth?client_id=facebook_id&redirect_uri=%2Fcallback&response_type=code&scope=email") | ||
end | ||
|
||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock | ||
.stub(:post, "https://graph.facebook.com/v2.9/oauth/access_token") | ||
.with( | ||
body: "client_id=facebook_id&client_secret=facebook_secret&redirect_uri=%2Fcallback&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-type" => "application/x-www-form-urlencoded"}) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"token_type" : "Bearer", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "user" | ||
}) | ||
) | ||
describe MultiAuth::Provider::Facebook do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("facebook", "/callback").authorize_uri | ||
uri.should eq("https://www.facebook.com/v2.9/dialog/oauth?client_id=facebook_id&redirect_uri=%2Fcallback&response_type=code&scope=email") | ||
end | ||
|
||
WebMock | ||
.stub(:get, "https://graph.facebook.com/v2.9/me?fields=id,name,last_name,first_name,email,location,about,website") | ||
.to_return( | ||
body: %({ | ||
"name" : "Sergey", | ||
"id" : "3333" | ||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock | ||
.stub(:post, "https://graph.facebook.com/v2.9/oauth/access_token") | ||
.with( | ||
body: "client_id=facebook_id&client_secret=facebook_secret&redirect_uri=%2Fcallback&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-type" => "application/x-www-form-urlencoded"}) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"token_type" : "Bearer", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "user" | ||
}) | ||
) | ||
) | ||
|
||
WebMock | ||
.stub(:get, "https://graph.facebook.com/v2.9/me?fields=id,name,last_name,first_name,email,location,about,website") | ||
.to_return( | ||
body: %({ | ||
"name" : "Sergey", | ||
"id" : "3333" | ||
}) | ||
) | ||
|
||
user = MultiAuth.make("facebook", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
user = MultiAuth.make("facebook", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
|
||
user.name.should eq("Sergey") | ||
user.uid.should eq("3333") | ||
end | ||
user.name.should eq("Sergey") | ||
user.uid.should eq("3333") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,34 @@ | ||
require "../spec_helper" | ||
|
||
describe MultiAuth do | ||
context "github" do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("github", "/callback").authorize_uri | ||
uri.should eq("https://github.com/login/oauth/authorize?client_id=github_id&redirect_uri=&response_type=code&scope=user%3Aemail") | ||
end | ||
|
||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock.stub(:post, "https://github.com/login/oauth/access_token") | ||
.with( | ||
body: "client_id=github_id&client_secret=github_secret&redirect_uri=&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-type" => "application/x-www-form-urlencoded"} | ||
) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"token_type" : "Bearer", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "user" | ||
}) | ||
) | ||
|
||
WebMock.stub(:get, "https://api.github.com/user") | ||
.to_return(body: File.read("spec/support/github.json")) | ||
|
||
user = MultiAuth.make("github", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
|
||
user.email.should eq("[email protected]") | ||
end | ||
end | ||
describe MultiAuth::Provider::Github do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("github", "/callback").authorize_uri | ||
uri.should eq("https://github.com/login/oauth/authorize?client_id=github_id&redirect_uri=&response_type=code&scope=user%3Aemail") | ||
end | ||
|
||
context "facebook" do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("github", "/callback").authorize_uri | ||
uri.should eq("https://github.com/login/oauth/authorize?client_id=github_id&redirect_uri=&response_type=code&scope=user%3Aemail") | ||
end | ||
|
||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock.stub(:post, "https://github.com/login/oauth/access_token") | ||
.with( | ||
body: "client_id=github_id&client_secret=github_secret&redirect_uri=&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-type" => "application/x-www-form-urlencoded"} | ||
) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"token_type" : "Bearer", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "user" | ||
}) | ||
) | ||
|
||
WebMock.stub(:get, "https://api.github.com/user") | ||
.to_return(body: File.read("spec/support/github.json")) | ||
|
||
user = MultiAuth.make("github", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
|
||
user.email.should eq("[email protected]") | ||
end | ||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock.stub(:post, "https://github.com/login/oauth/access_token") | ||
.with( | ||
body: "client_id=github_id&client_secret=github_secret&redirect_uri=&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-type" => "application/x-www-form-urlencoded"} | ||
) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"token_type" : "Bearer", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "user" | ||
}) | ||
) | ||
|
||
WebMock.stub(:get, "https://api.github.com/user") | ||
.to_return(body: File.read("spec/support/github.json")) | ||
|
||
user = MultiAuth.make("github", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
|
||
user.email.should eq("[email protected]") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require "../spec_helper" | ||
|
||
describe MultiAuth::Provider::Google do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("google", "/callback").authorize_uri | ||
uri.should eq("https://accounts.google.com/o/oauth2/v2/auth?client_id=google_id&redirect_uri=%2Fcallback&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuser.emails.read+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuser.phonenumbers.read+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuser.addresses.read+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcontacts.readonly") | ||
end | ||
|
||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock.stub(:post, "https://www.googleapis.com/oauth2/v4/token") | ||
.with( | ||
body: "client_id=google_id&client_secret=google_secret&redirect_uri=%2Fcallback&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-Length" => "111", "Host" => "www.googleapis.com", "Content-type" => "application/x-www-form-urlencoded"} | ||
) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"token_type" : "Bearer", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "user" | ||
}) | ||
) | ||
|
||
WebMock.stub(:get, "https://people.googleapis.com/v1/people/me?requestMask.includeField=person.addresses,person.biographies,person.bragging_rights,person.cover_photos,person.email_addresses,person.im_clients,person.interests,person.names,person.nicknames,person.phone_numbers,person.photos,person.urls") | ||
.to_return(body: File.read("spec/support/google.json")) | ||
|
||
user = MultiAuth.make("google", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
|
||
user.email.should eq("[email protected]") | ||
end | ||
end | ||
end | ||
|
||
context "facebook" do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("github", "/callback").authorize_uri | ||
uri.should eq("https://github.com/login/oauth/authorize?client_id=github_id&redirect_uri=&response_type=code&scope=user%3Aemail") | ||
end | ||
|
||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock.stub(:post, "https://github.com/login/oauth/access_token") | ||
.with( | ||
body: "client_id=github_id&client_secret=github_secret&redirect_uri=&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-type" => "application/x-www-form-urlencoded"} | ||
) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"token_type" : "Bearer", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "user" | ||
}) | ||
) | ||
|
||
WebMock.stub(:get, "https://api.github.com/user") | ||
.to_return(body: File.read("spec/support/github.json")) | ||
|
||
user = MultiAuth.make("github", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
|
||
user.email.should eq("[email protected]") | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,43 @@ | ||
require "../spec_helper" | ||
|
||
describe MultiAuth do | ||
context "vk" do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("vk", "/callback").authorize_uri | ||
uri.should eq("https://oauth.vk.com/authorize?client_id=vk_id&redirect_uri=%2Fcallback&response_type=code&scope=email") | ||
end | ||
describe MultiAuth::Provider::Vk do | ||
it "generates authorize_uri" do | ||
uri = MultiAuth.make("vk", "/callback").authorize_uri | ||
uri.should eq("https://oauth.vk.com/authorize?client_id=vk_id&redirect_uri=%2Fcallback&response_type=code&scope=email") | ||
end | ||
|
||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock | ||
.stub(:post, "https://oauth.vk.com/access_token") | ||
.with( | ||
body: "client_id=vk_id&client_secret=vk_secret&redirect_uri=%2Fcallback&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-Length" => "103", "Host" => "oauth.vk.com", "Content-type" => "application/x-www-form-urlencoded"}) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "email", | ||
"user_id" : "3333", | ||
"email" : "[email protected]" | ||
}) | ||
) | ||
it "fetch user" do | ||
WebMock.wrap do | ||
WebMock | ||
.stub(:post, "https://oauth.vk.com/access_token") | ||
.with( | ||
body: "client_id=vk_id&client_secret=vk_secret&redirect_uri=%2Fcallback&grant_type=authorization_code&code=123", | ||
headers: {"Accept" => "application/json", "Content-Length" => "103", "Host" => "oauth.vk.com", "Content-type" => "application/x-www-form-urlencoded"}) | ||
.to_return( | ||
body: %({ | ||
"access_token" : "1111", | ||
"expires_in" : 899, | ||
"refresh_token" : null, | ||
"scope" : "email", | ||
"user_id" : "3333", | ||
"email" : "[email protected]" | ||
}) | ||
) | ||
|
||
WebMock | ||
.stub(:get, %(https://api.vk.com/method/users.get?fields=about,photo_max_orig,city,country,domain,contacts,site&user_id="3333"&v=5.52)) | ||
.to_return( | ||
body: %({"response": [{ | ||
"first_name" : "Sergey", | ||
"last_name" : "Makridenkov", | ||
"id" : 3333 | ||
}]}) | ||
) | ||
WebMock | ||
.stub(:get, %(https://api.vk.com/method/users.get?fields=about,photo_max_orig,city,country,domain,contacts,site&user_id="3333"&v=5.52)) | ||
.to_return( | ||
body: %({"response": [{ | ||
"first_name" : "Sergey", | ||
"last_name" : "Makridenkov", | ||
"id" : 3333 | ||
}]}) | ||
) | ||
|
||
user = MultiAuth.make("vk", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
user = MultiAuth.make("vk", "/callback").user({"code" => "123"}).as(MultiAuth::User) | ||
|
||
user.name.should eq("Makridenkov Sergey") | ||
user.uid.should eq("3333") | ||
end | ||
user.name.should eq("Makridenkov Sergey") | ||
user.uid.should eq("3333") | ||
end | ||
end | ||
end |
Oops, something went wrong.