Define multiple auth routes with omniauth - ruby-on-rails-4

I'm versioning my rails app and I want to be able to authenticate an user with 2 different routes :
get 'v1/auth/:provider' => 'The omniauth method containing the appropriate callback'
get 'v1/auth/:provider/callback => 'v1/sessions#create'
get 'v2/auth/:provider' => 'The omniauth method containing the appropriate callback'
get 'v2/auth/:provider/callback => 'v2/sessions#create'
Is it possible to "hack" the prefix_path attributes so I can generate both routes ?

Related

AWS PHP SDK Cognito User Auth

How can I verify if a user is logged in on my services with AWS PHP SDK?
I am logging them with :
$result = $this->awsCognitoClient->adminInitiateAuth([
'AuthFlow' => 'ADMIN_NO_SRP_AUTH',
'ClientId' => $this->appClientID,
'UserPoolId' => $this->userPoolID,
'AuthParameters' => [
'USERNAME' => $userName,
'PASSWORD' => $password,
],
]);
That provides a session token. I want to send that token to another of my services and in that other service I want to check if the token is valid or not. How should I proceed?
Is this the best way or is there a better method to authenticate my user?
To solve this issue i created a singleton instance of an AWSAutWrapper and i share the accesstoken with other services.

Creating Oauth callback function in python. I there is a webserver should sends me Token and I want to react to the token if it's correct by call back

I want to make the same function but in Python Django how can I do that
because I
want to make authentication for login using Oauth 2.0
public function callback(Request $request){
$response = Http::post('https://oauth.zid.sa' . '/oauth/token', [
'grant_type' =>'authorization_code',
'client_id' => 48,
'client_secret' => 'LsswUNyWTjyKT9AsXnpsv3FnG4glSNZQ5SM3YRnD',
'redirect_uri' => 'http://client.test/oauth/callback',
'code' => $request->code // grant code]);}

OTRS generic interface rest authentication

I'm trying to consume the OTRS generic interface. The rest service is created by the import functionallity. I found the files needed for import here Consuming OTRS TicketConnector from .NET apps
My problem is when I try to consume the interface for example with a curl command
curl http://<user>:<password>#<server-ip>:<port>/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/<Ticket-id> -X GET
The result of the command is
{"Error":{"ErrorCode":"TicketGet.AuthFail","ErrorMessage":"TicketGet: Authorization failing!"}}
I tried every user/password combination that makes sense to me. I tried the otrs admin account, agent account, customer account, root account of the server, EVERYTHING! I can't find a information in the docs that states wich account type is needed.
Here are some information that are printed out by the webservice debugger
Communication sequence started
$VAR1 = {
'DOCUMENT_ROOT' => '/srv/www/htdocs',
'GATEWAY_INTERFACE' => 'CGI/1.1',
'HTTP_ACCEPT' => '*/*',
'HTTP_HOST' => '<server-name>',
'HTTP_USER_AGENT' => 'curl/7.39.0',
'MOD_PERL' => 'mod_perl/2.0.4',
'MOD_PERL_API_VERSION' => '2',
'PATH' => '/sbin:/usr/sbin:/usr/local/sbin:/root/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/X11R6/bin:/usr/games:/usr/lib/mit/bin:/usr/lib/mit/sbin',
'PATH_INFO' => '/Webservice/GenericTicketConnectorREST/Ticket/<ticket-id>',
'PATH_TRANSLATED' => '/srv/www/htdocs/Webservice/GenericTicketConnectorREST/Ticket/<ticket-id>',
'QUERY_STRING' => '',
'REMOTE_ADDR' => '<server-ip>',
'REMOTE_PORT' => '56065',
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/<ticket-id>',
'SCRIPT_FILENAME' => '/opt/otrs/bin/cgi-bin/nph-genericinterface.pl',
'SCRIPT_NAME' => '/otrs/nph-genericinterface.pl',
'SERVER_ADDR' => '<server-ip>',
'SERVER_ADMIN' => '<admin-account>',
'SERVER_NAME' => '<server-name>',
'SERVER_PORT' => '80',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'SERVER_SIGNATURE' => '<address>Apache/2.2.12 (Linux/SUSE) Server at <server-name> Port 80</address>
',
'SERVER_SOFTWARE' => 'Apache/2.2.12 (Linux/SUSE)'
};
Deteced operation TicketGet
No data provided
Incoming data before mapping
$VAR1 = {
'RequestMethod' => 'GET',
'TicketID' => '<ticket-id>'
};
TicketGet.AuthFail
TicketGet: Authorization failing!
Outgoing data before mapping
$VAR1 = {
'Error' => {
'ErrorCode' => 'TicketGet.AuthFail',
'ErrorMessage' => 'TicketGet: Authorization failing!'
}
};
Long story short: what type of authentication or user type otrs expects to access the generic interface?
In found my mistake. The way I passed the login credentials to the service was wrong.
In my case the user is a agent user.
Here is a working curl command for my service:
curl http://<server-ip>:<port>/otrs/nph-genericinterface.pl/Webservice/GenericTicketConnectorREST/Ticket/<ticket-id>?UserLogin=<username>\&Password=<password> -X GET

How to test slugged url with rspec

I have an rails application where i used slugged urls. How can i test those urls with Rspec.
rake routes is generating following results
new_user_session GET /login(.:format) sessions#new
user_session POST /login(.:format) sessions#create
bays GET /:slug/bays(.:format) bays#index
POST /:slug/bays(.:format) bays#create
new_bay GET /:slug/bays/new(.:format) bays#new
edit_bay GET /:slug/bays/:id/edit(.:format) bays#edit
bay GET /:slug/bays/:id(.:format) bays#show
PATCH /:slug/bays/:id(.:format) bays#update
PUT /:slug/bays/:id(.:format) bays#update
DELETE /:slug/bays/:id(.:format) bays#destroy
Now when i run rpec for bays controller, i caught with following error.
Failure/Error: get :index, {}, valid_session
ActionController::UrlGenerationError:
No route matches {:action=>"index", :controller=>"bays"}
Using
rspec-rails (3.0.1)
rails (4.0.0)
As you have defined it... bays index requires a :slug parameter. According to the error message, you have passed no slug to this route. You must either pass :slug (eg get :index, :slug => "1234", valid_session) or redefine the route to not need it.
for testing routes in rspec... That's a basic part of rspec: rspec routing specs
in your case it'd be something like:
{ :get => "/1234/bays" }.
should route_to(
:controller => "bays",
:slug => "1234"
)
For rspec 3.x you can go with:
scenario 'get correct slug', :type => :routing do
expect(get("/models/slug")).to route_to(:controller => "controller_name", :action => 'action_name', :id => "your_slug_name")
end
Note the type: :routing definition before the block.
More info here.

Facebook FQL is deprecated, but there's no way to directly get friend_count with Graph API?

Using FQL I can easily get the friend count of a user with:
SELECT uid,friend_count FROM user WHERE uid IN (<list of user ids/>)
But it looks like with Graph API, I have to make requests until the pagination runs out, and then count how many results were returned using something like:
array(
'method' => 'GET',
'relative_url' => 'me/friends?access_token='. $token
)
I tried using
array(
'method' => 'GET',
'relative_url' => 'me/friends?summary=true&access_token='. $token
)
but that didn't work. Is there a single Graph API request that can get a user's friend count? If not, how do I make a feature request?
Facebook implemented this feature for the Graph API since the release of v2.1:
/friends edge on the User object now provides access to total friend count. This is retroactively supported in v2.0 as well.
Graph-API-v2.1