Based on this Can anyone explain Laravel 5.2 Multi Auth with example
i will like to implement custom authentication on my app for the admin and users section but the whole concept is confusing maybe it is new to me in laravel 5.2 (my version) but at this stage i can say if i am getting it right or wrong but this is the error that is displaying.
InvalidArgumentException in CreatesUserProviders.php line 40:
Authentication user provider [] is not defined.
so i have done what #imrealashu answered but still i have issues.
It means that you didn't pass the guard like this:
auth('admin')->user();
//or
Auth::guard('admin')->user();
Or when you call the middleware auth in your controller, you need to pass the guard:
$this->middleware('auth:admin');
This video explains it https://www.youtube.com/watch?v=Vxh2ikaydfo (In spanish but its understandable )
I got that error when I tried to change in auth.php:
'provider' => 'users'
to
'provider' => 'user'
because my database table was user, not users.
That's not necessary. I just had to add to the User Eloquent class:
protected $table = 'user';
Related
We are using Doorkeeper gem to authenticate our users through an API. Everything is working fine since we've implemented it few years ago, we are using the password grant flow as in the example:
resource_owner_from_credentials do |_routes|
user = User.active.find_for_database_authentication(email: params[:username])
if user&.valid_password?(params[:password])
sign_in(user, force: true)
user
end
end
Doorkeeper is coupled with Devise, which enable reconfirmable strategy. As you can see in the code above, we are only allowing active users (a.k.a users with a confirmed email) to connect:
User.active.find_.....
Problem
Our specifications changed and now we want to return a different error on login (against /oauth/token) depending if the user has confirmed its email or not.
Right now, if login fails, Doorkeeper is returning the following JSON:
{
"error": "invalid_grant",
"error_description": "The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client."
}
Ideally, we want to be able to return a custom description if and only if the current email trying to login is unconfirmed
We've checked the documentation on Doorkeeper but it does not seems to have an easy way (if any at all) to do this. The fact that resource_owner_from_credentials method is located in the config adds too much magic and not enough flexibility.
Any ideas ?
Ok so after digging a little bit, we found an easy way to work around this issue by overriding Doorkeeper::TokensController.
# frozen_string_literal: true
class TokensController < Doorkeeper::TokensController
before_action :check_if_account_is_pending, only: :create
private
def check_if_account_is_pending
user = User.find_by(email: params['username'])
render json: unconfirmed_account_error if user && !user.confirmed?
end
def unconfirmed_account_error
{ error: 'invalid', error_description: 'You must validate your email address before login' }
end
end
We also needed to make sure the routes were pointing to the custom controller:
use_doorkeeper do
controllers tokens: 'tokens'
end
Hope it can helps someone in the future
Wishing You a Happy New year I start with my first problem of the year
here's what I do in login method of user controller:
Yii::import('ext.eoauth.*');
$ui = new EOAuthUserIdentity(
array(
//Set the "scope" to the service you want to use
'scope'=>'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile',
'provider'=>array(
'request'=>'https://www.google.com/accounts/OAuthGetRequestToken',
'authorize'=>'https://www.google.com/accounts/OAuthAuthorizeToken',
'access'=>'https://www.google.com/accounts/OAuthGetAccessToken',
)
)
);
if ($ui->authenticate()) {
$user=Yii::app()->user;
$user->login($ui);
$this->redirect(array('loggedin'));
}
else
throw new CHttpException(401, $ui->error);
its logged and in place of name it display the token key.. i need to get email at least to store it to db... Please help me out.. thanks in advance
In the UserIdentity class, You need to write a line i.e
$this->setState('name', 'value');
This is used to set the `Yii::app()->user->name
so if you set it as
$this->setState('name', $record->email);
$this->errorCode=self::ERROR_NONE;
in your UserIdentity class then Yii::app()->user->name will return you the email or whatever you want
I tried lot to get user detail by using above code.. Unfortunately I failed.. Then I started with eauth integration..I downloaded the demo example in the url and added extension to my extension folder inside protected and configured the main.php.. I got integration of more than 10 login integration.. I commented the services extension inside component tag in main.php to get Google and Yahoo login integration.. It works... Which made me to access the user name also.. Thanks for support..
demo of eauth
For integration find the link below
Integration link for eauth
I am using Koala gem and in my UI i have an share link. How can i share the posts using the post id. Can it be done like this.
#facebook = FacebookToken.first
#graph = Koala::Facebook::API.new(#facebook.access_token)
#graph.put_object(params[:post_id], "share",:message => "First!")
It gives the following error
Koala::Facebook::ClientError: type: OAuthException, code: 240, message: (#240) Requires a valid user is specified (either via the session or via the API parameter for specifying the user. [HTTP 403]
I thing something going wrong with permission. I have added the following permission in the fave bool app
"share_item,manage_pages,publish_stream,read_stream,offline_access,create_event,read_insights, manage_notifications"
Do I need to some other permission to share a post using post id
The first parameter in put_object is not the post ID, but the ID of who is sharing it, be it a page or user.
So instead of saying:
#graph.put_object(params[:post_id] ...
You would say:
//the current user
#graph.put_object('me' ...
or
//any user that you have a UID for
#graph.put_object(#user.uid ...
or
//a page that you have post permissions for
#graph.put_object(#facebook_page.id ...
Also in a future version of Koala, put_object will be a bit different, and you should go ahead and switch over to put_connection.
While trying to create a cart via the Magento API, I am having trouble adding an existing user as the owner of the cart. I am working with the documentation they provide here:
http://www.magentocommerce.com/wiki/doc/webservices-api/api/cart#cart_customer.set
I called "customer.info" using my specific customerId, then just passed the results to that cart_customer.set method, praying that was what it was asking for. It returned (from PHP)
Fatal error: Uncaught SoapFault exception: [1045] Customer's mode is unknown in ...
I looked at the example at the bottom of the above referenced page and they only had an example for a new guest user, 'mode' set to 'guest'. I was wondering if anyone knew what the other options were for that 'mode' key? Documentation on that data structure in general would be a great help.
Thanks.
Via my own comment:
Ah ha! Found buried in their forum:
$customer = array( 'entity_id' => 6, 'mode' => 'customer' ); via http://www.magentocommerce.com/boards/viewthread/232778 I guess that is all you need to pass. This isn't really a great explanation but it does solve the original problem.
Just gonna flag this one as done.
My application gets approved and a user gets an access token and extended permissions which include offline_access and publish_stream.
I want to be able to post from inside my model. This would require me to make an
https://graph.facebook.com/FBUSER_ID/feed
plus some parameters and access token, app_id, app_secret.
I have the access token and FBUSER_ID.
What I don't know how to do is put it all together in the model.
Could anyone point me in the right direction?
I already have a facebook application. I need to know how to post from the server to a users wall
**Thanks to the answer below I was able to get it working with the following:
access_token = "AAACvmqy1nYoBAAZCkGXbVgRwcBv******ZAMjsLxKxR7DaZBE0NxY8ZBGBW1q2mzsB9TDT0RvgeQcDdnyFJNAYRf0icnhlbikZD"
appID = '1776938807888574888888888882'
message = 'test_message'
userID = '75164088804088888'
uri = URI.parse("https://graph.facebook.com/#{userID}/feed")
req = Net::HTTP::Post.new(uri.path)
result = req.set_form_data({:access_token => access_token , :message => message, :app_id => appID })
sock = Net::HTTP.new(uri.host, 443)
sock.use_ssl = true
sock.start do |http|
response = http.request(req)
end
IMPORTANT: at the top of the controller or model add:
require 'openssl'
First you have to create a Facebook application here. By the app_id and app_secret of created application, you will ask user to give "publishing feed" permission to your application. While getting this permissions you get also the access token for posting the users wall.
You can get detailed info about authentication here:
https://developers.facebook.com/docs/authentication/
And you can get info about publishing here on the Publishing section:
http://developers.facebook.com/docs/reference/api/
With ruby, your need is just making an HTTP Post. This may be an example for this:
Net::HTTP.post_form(URI.parse('https://graph.facebook.com/FBUSER_ID/feed'),
{'access_token' => 'ACCESS_TOKEN', 'message' => 'MESSAGE'})