In one of the website I need login with facebook account. I am using following code on face book login button.
string callbackUrl = "https://www.facebook.com/connect/login_success.html";
Response.Redirect(string.Format("https://graph.facebook.com/oauth/" +
"authorize?client_id={0}&redirect_uri={1}&scope=offline_access," +
"publish_stream,read_stream,publish_actions,manage_pages",
1448xxxxxx781763, callbackUrl));
it shows 'Success' with access token url for a brief moment and then a security message appears and the access token is lost. How can I capture the access token? Thanks
Use your own domain for the callbackURL, not facebook.com.
That being said, you are better off by using the JavaScript SDK for login: https://developers.facebook.com/docs/reference/javascript/FB.login/v2.0
That way you don´t have to worry about the Access Token at all.
Related
I am working with the functionality to integrate ADFS login page with my application.
Flow
User will try to visit page. Here system will try to authenticate user.
System will redirect user to ADFS login page.
User will enter login information. If user is authenticated then user will be redirected back to the application with authorized token information.
I am facing difficulties to read the token information when the page is redirected back.
I tried
I am able to redirect page to ADFS login page and also can redirect back to my system if the user is authenticated using below url format:
https://adfs-domain-name/adfs/ls
Please find the below code snippet which I am using after getting back the page to read token information.
ClaimsPrincipal claimsPrincipal = Thread.CurrentPrincipal as ClaimsPrincipal;
bool IsAuthenticated = claimsPrincipal.Identity.IsAuthenticated;
int ClaimCount = claimsPrincipal.Claims.Count();
Here I am getting IsAuthenticated as false and ClaimCount as 0 result.
Is there anything incorrect in my code or way to connect ADFS login page ?
Can anyone help me to fix this ?
Please let me know if you have any concern or query or if I am missing something.
In short, I would recommend following this tutorial:
https://learn.microsoft.com/en-us/windows-server/identity/ad-fs/development/enabling-openid-connect-with-ad-fs-2016
I followed the steps in there and got it to work (using OAuth2 / OpenID connect). There are some other interesting resources on that site, too.
Some more pointers:
1) For using OAuth2 the login URL on the ADFS server should be something like:
https://adfs.contoso.com/adfs/oauth2/authorize?[parameters]
The URL parameters are nicely documented here:
https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code
2) You can then use the ADAL libraries for the frontend and backend code. In essence, the frontend code will put together the aforementioned login URL and keep the token in the browser's session storage to be sent with each request. The backend library will verify and decode the tokens (into ClaimsPrincipal) for you. You can find the appropriate library components here:
https://learn.microsoft.com/en-us/azure/active-directory/develop/active-directory-authentication-libraries
Ah, yeah, I know these components and docs describe Azure AD (ADFS in the cloud), but what they run there is essentially the same as ADFS 4.0 on Windows Server 2016.
i want to implement a REST webservice in my wordpress blog. Visitors or other users can select images from my OneDrive Account and order them.
My problem is when i get the authentication code i must enter my password für OneDrive. After that i get the access_token. The access_token has only a runtime for 1 hour.
When i order i new access_token the code is expired and i must get a new authentication code with my user password.
How i can implement a webservice for OneDrive without enter my own password everytime?
Thanks for your help.
When you get the access_token through the code flow when authing you should also see a refresh_token come back (provided you requested the wl.offline_access scope). You should be able to use that to get a new access_token by using the this process without requiring user interaction.
Can i log in to my Facebook account (Knowing user id and password), in the server using Facebook php-sdk, and without need to click any URL?
If yes, please explain.
It is against Facebook's Terms of Service to use a user's email address and password to login to their account. You should instead use the Facebook API to achieve this, but it requires manual login by a user.
There are ways of achieving automatic login using credentials, but since it's not allowed, I won't go into detail. Facebook also detects and prevents most of the common method of auto-login.
I am trying to authenticate a user with Azure Mobile Services from within a ASP.NET Web Form (.aspx.cs).
I have provisioned my Mobile Service to authenticate with Facebook using the steps described here: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-windows-store-dotnet-get-started-users/.
This tutorial, however, describes authenticating in a XAML app where popups can appear, but I need to Log the user in within a postback of the web form, where showing a popup is impossible.
According to the docs I can do this by using the LoginAsync() function, like this":
MobileServiceClient client = MyAppsMobileClient.getClient(); //this handles setting the app ID and url
MobileServiceUser user = client.LoginAsync("facebook","");
Now, my problem is the second argument of this function. According to the docs, this is of type JObject, and apparently it is a JSON object I obtain from facebook when I first log in. Now, I can make a simple Login form for the user to enter his facebook ID and password, but I still don't know how to obtain the JObject I need to log in to Mobile Services. Do I need to delve into the Facebook APIs? Is this done using Ajax? Any examples, guides or tutorials on this would be welcome.
You can create a jObject from the data received from Facebook like this:
var token = JObject.FromObject(new
{
access_token = "YOUR TOKEN HERE"
});
This sample was taken from this SO thread:
Azure Mobile Service LoginAsync with Facebook Token is Unauthorized
And here you can read how to obtain an access token from Facebook using JavaScript:
Obtaining an Access Token
I need to write from my site to my Facebook page.
I am using this c# SDK: enter link description here
I found the Facebook documentation : enter link description here
To make this operations, i need to get a token before, like documented here (Page login section) enter link description here
If i try to type the url in the browser, like in the example and using my application data, the token will be give me back in the URL.
This is the sample url that will return my token in the url:
https://www.facebook.com/dialog/oauth?
client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=manage_pages&
response_type=token
My question is: i'm using asp.net MVC, how can i call this url and get the returned token (from url); WebResponse method does not let me to have the returned url.
which class and method should i use into my controller?
tks
i solved bypassing this step.
I manually get the token for the admininistrator of the page and after i can obtain the token of every page administrated by the user.
Then i store it into web.config (application settings).
With this token i can publish to my wall from my server when i want.
See FB Page Section