Asp.net webfroms Google login not working - asp.net

I have the project and users are login into their account by using Google login I created another project in the Google console developer portal to login with gmail now I got this below error message
Code: 403 Message: Legacy People API has not been used in project {PROJECTID} before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?project={PROJECTID} then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
I followed this URl and https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?project={PROJECTID}
but the page show up this below error many times I click on Retry button nothing has changed.
Error alert in Google Console
I have followed this articles https://www.aspsnippets.com/Articles/Login-with-Google-Account-API-in-ASPNet-and-get-Google-Plus-Profile-details.aspx
The code
GoogleConnect.ClientId = "CODE-1545454545545bpqhocrakp.apps.googleusercontent.com"
GoogleConnect.ClientSecret = "KHDFIUHUHDJHSLDSKJ"
GoogleConnect.RedirectUri = "https://mywebsitedomain.com/Login"
Dim code As String = Request.QueryString("code")
Dim json As String = GoogleConnect.Fetch("me", code)
Dim profile As GoogleProfile = New JavaScriptSerializer().Deserialize(Of GoogleProfile)(json)

Related

owin active directory token validation random slowness and error

I am facing some random authorisation problem when using following code to authenticate against ad active directory (I have a web api).
I believe this code will send a validation request to our azure active directory, but randomly we got validation error and some times it can take a while to get validation result back.
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = Constants.AzureActiveDirectoryTenant,
TokenValidationParameters = new TokenValidationParameters
{
ValidateAudience = true,
// These values will be checked against what is received in the access token.
ValidAudiences = Constants.AzureActiveDirectoryValidAudiences
}
});
Is it possible to understand why validation failed? Also about the speed, is it possible to create some custom method to cache a token on my web site? So I don't need to validate every request to AD all the time.
You can try the Microsoft.Owin.Diagnostics nuget package to check the logs.
Alternatively, for a remote debug:
In Cloud Explorer in visual studio, find you web app and select "Remote Debugging."
Then publish your site in Debug mode.
In the portal, enable it by going to Application settings > Debugging > Remote Debugging > On

ASP.NET - Authentication against Active Directory fails because of NativeObject binding

I am working on an academic project, and we have to authenticate against Active Directory Domain Services accounts from a web application.
I have followed this msdn tutorial, and as specified I changed the ldap path in the Login_Click() function.
Everything went fine, but when I tried to login in the web app, I got this:
Error authenticating. Error authenticating user. Logon Failure:
unknown user name or bad password ... at
System.DirectoryServices.DirectoryEntry.get_NativeObject()...
Here is the error screenshot:
Web app's error screen
For information, I filled the adPath like this (in the Login_Click() method):
string adPath = "LDAP://DC.datacenter.mex.am.company.net/"
And we also tried with this :
string adPath = "LDAP://DC.datacenter.mex.am.company.net/DC=datacenter,DC=mex,DC=am,DC=company,DC=net/"
The credentials we tried to login with are perfectly valids, because we tested them to access to Active Directory accounts ... But the same credentials don't work from the asp .net web app !!!
I searched everywhere on the net, but came with nothing ...
Has anyone got an idea about that ??
You can do authentication via PrincipalContext
using (var context = new PrincipalContext(ContextType.Domain,
yourdomain,
UsernameforAD,
ADUserPassword)
{
bool isAuthenticated= context.ValidateCredentials(username,password);
}

App Service Refresh Tokens

Has anything changed with regard to refreshing Google tokens using the MobileServiceClient against App Service. I used to be able to refresh Google tokens in my Xamarin Forms app using the MobileServiceClient. Now, after logging in, any attempt to refresh returns forbidden.
My login code is as follows:
public class Authentication : IAuthentication
{
public async Task<MobileServiceUser> LoginAsync(MobileServiceClient mobileClient, MobileServiceAuthenticationProvider provider)
{
return await mobileClient.LoginAsync(
Forms.Context,
provider,
new Dictionary<string, string>()
{
{ "access_type", "offline" }
});
}
}
My refresh code is:
var user = await MobileService.RefreshUserAsync();
The refresh fails even if I try refreshing immediately after my successful login. The Token Store is configured "On". The refresh works fine against the Microsoft provider. It was working a few months ago.
Microsoft.Azure.Mobile.Client v3.1.0
Microsoft.Azure.Mobile.Server v2.0.0
Browsing directly to https://[my-website].azurewebsites.net/.auth/login/google returns "You have successfully signed in"
Browsing directly to https://[my-website].azurewebsites.net/.auth/me returns [{"access_token":"ya29.Gl3ZAw6B1H0cT_e6vRlHgwQd0U-bcDSKo_CGQ9wKwPH8H-EbtNojP61JSzDaiIgSzU14Pr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bEpk-h4_HU5Ld1lNqYG-hgzEdUsJm_uspJk7FggwcfuPw-YQJr-GXbqd2Om9fmgGPrPrsFy7EzPGL27q_BIY3cOLEVX0e3tbAAVhxFCri835nBKdkYOP9X2g6wSuMWCq6iPOjFzErhVYR_WUwi5H-UW6mJHswcAfs_3Hwwt9RzCqfcyS1ZaehQVJE5B3uvK9WmAOrbD7uyEQmSli_zRWw","provider_name":"google","user_claims":[{"typ":"iss","val":"https://accounts.google.com"},{"typ":"iat","val":"1484920821"},{"typ":"exp","val":"1484924421"},{"typ":"at_hash","val":"XGkwj8ZbeOF_cwJjjxJLFw"},{"typ":"aud","val":"748073468649-jtm59t7mlcsci89lokbuvseoann28bgq.apps.googleusercontent.com"},{"typ":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier","val":"101812912381918040847"},{"typ":"email_verified","val":"true"},{"typ":"azp","val":"748073468649-jtm59t7mlcsci89lokbuvseoann28bgq.apps.googleusercontent.com"},{"typ":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress","val":"[my-googleemail]"},{"typ":"name","val":"[my - name]"},{"typ":"picture","val":"https://lh5.googleusercontent.com/-ZH5LACTaA4I/AAAAAAAAAAI/AAAAAAAAAAA/AKB_U8tijfyeCwBOmYLsNc8AFIq3CTbaTw/s96-c/photo.jpg"},{"typ":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname","val":"[my-givenname]"},{"typ":"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname","val":"[my-surname]"}],"user_id":"[my-googleemail]"}]
Browsing directly to https://[my-website].azurewebsites/.auth/refresh returns "You do not have permission to view this directory or page"
If I repeat those steps with "microsoftaccount" the last refresh step works.
From Azure request tracking:
107. -GENERAL_FLUSH_RESPONSE_START
0 ms
Informational
108. -GENERAL_RESPONSE_HEADERS
Headers
Content-Type: text/html
Server: Microsoft-IIS/8.0
X-FE-DATA: AppId:Unknown-StatusCode
X-Powered-By: ASP.NET
DWAS-Handler-Name: BEGIN|403|80|0x0|CONFIG_SUCCESS|ExtensionlessUrlHandler-Integrated-4.0|###.##.##.###|\###.##.##.##\volume-4-default\&ApiApp=0
0 ms
Verbose
109. -GENERAL_RESPONSE_ENTITY_BUFFER
Buffer
You do not have permission to view this directory or page.
0 ms
Informational
110. -GENERAL_FLUSH_RESPONSE_END
BytesSent 400
ErrorCode The operation completed successfully.
(0x0)
Turns out that, with Google logins, refresh tokens are only issued upon the first login. I moved my Azure website and repointed the OAuth client settings so I was able to login but the Token Store no longer had a copy of the refresh_token sent with my initial Google login. Found the rest of the answer here.
Not receiving Google OAuth refresh token
According to your detailed information, I noticed that when you browsing directly to https://[my-website].azurewebsites.net/.auth/me, the response did not contain refresh_token. To isolate this issue, you could refer the following steps:
1.Browser https://brucechen-mobile.azurewebsites.net/.auth/login/google?access_type=offline and login with google account;
2.Access /.auth/me to retrieve my logged information as follows:
3.Browser /.auth/refresh to see whether you could get the response with 200 http status code.
Also, you could follow this official tutorial about refreshing user logins in App Service Mobile Apps to troubleshoot this issue. Additionally, you could leverage Fiddler to capture the detailed response when you invoke MobileService.RefreshUserAsync().

Facebook post on page

I'm using Facebook SDK 6 and Graph API to publish data from app (ASP.NET) to the page.
Firstly, my app (website) get access token using server flow as described here.
Next, it use this token to publish some text in my page:
Dim fb = New FacebookClient(accessToken)
Dim o As Dictionary(Of String, Object) = New Dictionary(Of String, Object)
o.Add("message", "some text...")
Dim result = fb.Post("/TfdTest/feed", o)
To test it, I browse my website. I allow my site change my facebook page and give permissions (publish_stream, manage_pages). The problem is that final feed appears in "Recent Posts by Others" section:
How can I post feed from page name, not from myself???
in order to use Graph API on behalf of a Page, you need to get Page access token - see here for more details: https://developers.facebook.com/docs/authentication/pages/
Authenticate the user and request the manage_pages permission
Get the list of pages the user manages using token from (1) - https://graph.facebook.com/me/accounts?access_token=USER_ACCESS_TOKEN
Parse the list and get the PAGE token - and use it to post to the feed.

fql.query method returns empty string in asp.net

I have developed a web application 3 months ago to show facebook users by searching username. To access facebook, I have downloaded facebook dll and got application key, and secret key from facebook.
My web application was working fine and displaying records from facebook. yesterday onwards, my application is not working fine. I could not get response when I search by name.
I have tested the fql in the facebook testAPI tool online. That time I can get response. but the same fql I used in my appliation but it could not get response from facebook when I search by name. If I search by uid i can get response from facebook.
here is my code-
facebook.Components.FacebookService fb = new FacebookService();
fb.ApplicationKey = "bfeefa69afdfe81975f0d6136ace3009";
fb.Secret = "9b672d682e1d8befd06382953fc2615b";
fb.IsDesktopApplication = false;
//the below fql gives response as xml.
//select name, profile_url from user where uid = '1730923544' -I can get response for this fql.
//the below fql does not give response as xml. But it gives empty string.
//the below fql does gives us response as xml when i try in facebook testAPI.
//select name, profile_url from user where name = 'Suresh Rajan' -I couldn't get response for this fql.
string s = fb.fql.query("select name, pic_square, profile_url from user where name = 'Suresh Rajan'");
if (String.IsNullOrEmpty(str1))
Response.Write("Empty Response");
else
Response.Write(str1 + " <br />");
how to search by name in facebook fql.
thanks
r.e
Yesterday Facebook was having issues with their API that may have prevented some queries from working. Try it again today and it might work.
Here is facebook's api status page where they report any ongoing issues with the API:
http://developers.facebook.com/live_status.php
If it's still not working for you then it's likely the fix that they deployed for yesterday's issue had a bug in it. Here is a similar bug that occured a while ago that sounds just like this one: http://bugs.developers.facebook.com/show_bug.cgi?id=1359. You should open a new bug on the facebook bug tracker if that's the case since that one is old and has already been closed.

Resources