I've been searching on the best way to get information my azure auth from facebook.
My app is getting the authentication and the id of the user! I am not sure what code I need next in order to get the information.
So far I have this
if (authenticated)
{
var client = new HttpClient();
var fbUser = await client.GetAsync(Appurl+".auth/me");
var response = await fbUser.Content.ReadAsStringAsync();
var jo = JObject.Parse(response);
var userName = jo["'typ':'user_id'"].ToString();
}
So far all the answers have left me clueless
I just need this to return name email and other Items I want.
I am sure this is an Json Parsing the wrong issue but I am not sure.
Please help!!!
I just need this to return name email and other Items I want. I am sure this is an Json Parsing the wrong issue but I am not sure.
If you visit https://yourmobileapp .azurewebsites.net/.auth/me from browser, and login with your FaceBook account. Then you could get the Json structs as following. It is a JArray . So please have a try to use following code, it works correctly on my side.
var ja = JArray.Parse(response);
var id = ja[0]["user_id"];
Before that we need to add email scope on the Azure portal, about how to add email scope, please refer to the screenshot.
Related
I am trying to read the Planner task for the users of my tenant. So I configured admin consent for "Tasks.Read", "Tasks.Read.Shared", "Groups.Read.All", "Groups.ReadWrite.All" for the app that is doing that.
Like mentioned here: https://learn.microsoft.com/de-de/graph/api/planneruser-list-tasks?view=graph-rest-1.0&tabs=http
I desined my code to get a token like mentioned here: https://briantjackett.com/2018/12/13/introduction-to-calling-microsoft-graph-from-a-c-net-core-application/
I get a token back and it is valid. (Checked with baerer token check tool.)
I thought that I could access the tasks from the Graph API like '/v1.0/users/{userId}/planner/tasks' but I get HTTP 401 back.
Can anyone give me the missing link? Thanks a lot.
_appId = configuration.GetValue<string>("AppId");
_tenantId = configuration.GetValue<string>("TenantId");
_clientSecret = configuration.GetValue<string>("ClientSecret");
_clientApplication = ConfidentialClientApplicationBuilder
.Create(_appId)
.WithTenantId(_tenantId)
.WithClientSecret(_clientSecret)
.Build();
var graphClient = GraphClientFactory.Create(new DelegateAuthenticationProvider(Authenticate));
var result = await graphClient.GetAsync($"/v1.0/users/{userId}/planner/tasks")
public async Task<string> GetTokenAsync()
{
AuthenticationResult authResult = await _clientApplication.AcquireTokenForClient(_scopes)
.ExecuteAsync();
return authResult.AccessToken;
}
private async Task Authenticate(HttpRequestMessage request)
{
var token = await GetTokenAsync();
request.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);
}
Reading tasks for other users is currently not allowed. A user can only read their assigned tasks. As an alternative, you can read the tasks in specific Plans, and sort out the users from that data, if you want to collect assignments from a set of Plans. You can provide feedback on this behavior in Planner UserVoice with the description of what you are trying to accomplish.
Additionally, application permissions are supported now, if that works for your scenario.
/v1.0/users/{userId}/planner/tasks is for getting tasks via getting a user, and you will need User permissions (User.Read.All) to get tasks via that call.
(Also Do you really need Groups.ReadWrite.All? Are you making changes to groups? -- it's not in your original description)
I try to make a push notification for my google assistant app.
I used the sendNotification Code form the google developer site: https://developers.google.com/actions/assistant/updates/notifications
I am coding Java.
Everything is working, expect getting the correct user id.
When I hardcode my user it works, but how do I get the user id in the code?
I tried following code:
Argument arg_userId = request.getArgument(ConstantsKt.ARG_UPDATES_USER_ID);
String userId = request.getUser().getUserId();
--> I get "java.lang.reflect.InvocationTargetException"
String userId = arg_userId.getRawText();
--> same Exception
There are two problems with the approach you're taking to get the notification ID:
The ID attached to the user object is deprecated and probably unavailable.
This wasn't the ID you wanted anyway.
In the response where the user finalizes the notification, that response includes an ID which you should get and store. Since you're using Java, the code might look something like this:
ResponseBuilder responseBuilder = getResponseBuilder(request);
Argument permission = request.getArgument(ConstantsKt.ARG_PERMISSION);
if (permission != null) {
Argument userId = request.getArgument(ConstantsKt.ARG_UPDATES_USER_ID);
// code to save intent and userID in your db
responseBuilder.add("Ok, I'll start alerting you.").endConversation();
} else {
responseBuilder.add("Ok, I won't alert you.");
}
return responseBuilder.build();
Is there a way to get "User Google Id" from the session in App Maker. In the documentation its only mentioned how to retrieve the email of the logged in user Session.getActiveUser().getEmail() but no where it says how to get the id. I need this because the user email might sometimes changes. So I need the user id to keep track of users and related permission tasks. Or is there something I'm missing out here in how this should be implemented.
Yet an easier way to find Google Id simply using the Directory model. Although its mentioned in documentation that there is a way to get current signed in user id ( which is Google Id), its not clearly stated how - maybe documentation could be improved here. Another problem is that in many occasions the email of current active user is referred to as the id for example in deprecated method Session.getActiveUser().getUserLoginId(). Anyways this is a proper way to get the id.
var query = app.models.Directory.newQuery();
query.filters.PrimaryEmail._equals = Session.getActiveUser().getEmail();
var result = query.run();
var GoogleId = result[0]._key;
So with this GoogleId you can safely relate different models with each other and not worry that database integrity might break if an already referenced user email is changed.
Relating the different models could be done simply by creating a model that acts as a wrapper model around the Directory model and storing GoogleId in it. Then linking that model to other models where you want to track user related data because unfortunately we can not directly link The Directory Model to other models.
A team member has figured it out. This should be done using Apps Script - which works within App Maker environment using server side script.
var GoogleUser = (function (){
/**
*
* #param {string} email
*/
function getUserObjByEmail(email){
// Same as using AdminDirectory class.
var apiUrl = "https://www.googleapis.com/admin/directory/v1/users/"+email+"?fields=id";
var token = ScriptApp.getOAuthToken();
var header = {"Authorization":"Bearer " + token};
var options = {
"method": "GET",
"headers": header
};
var response = JSON.parse(UrlFetchApp.fetch(apiUrl, options));
return response;
}
/**
*
* #param {string} email - User email.
*/
function getIdByEmail(email){
return getUserObjByEmail(email)['id'];
}
var publicApi = {
getIdByEmail: getIdByEmail
};
return publicApi;
})();
Note that using var apiUrl = "https://www.googleapis.com/admin/directory/v1/users/"+email+"?fields=id"; is not going to be asynchronously called because its already happening in the server.
Is this a dup of this question?
I think this will solve your problem, even though it's a bit of a hack.
I am using Auth0, And I want to retrieve all users of my client application.
Below is my code:
var apiClient = new ManagementApiClient("<<Token>>", new Uri("https://<<Domain>>/api/v2/users"));
var allClients = await apiClient.Users.GetAllAsync();
I am using token which includes Read:User permission in auth0.
But I am getting below error,
Path validation error: 'String does not match pattern ^.+\|.+$: users'
on property id (The user_id of the user to retrieve).
I read this arrticle, But I am not understanding, What changes I need to make in auth0.
https://auth0.com/forum/t/auth-renewidtoken-returns-a-user-id-validation-error/1151
What changed I need to make to solve it?
You need to create the ManagementApiClient in one of the following ways:
// Pass the base Uri of the API (notice it does not include the users path)
var api = new ManagementApiClient("[token]", new Uri("https://[account].auth0.com/api/v2"));
or
// Pass only the domain as a string
var api = new ManagementApiClient("[token]", "[account].auth0.com"));
You're including /users in the base API path which will then cause errors, like the one you observed.
Here I am using asp.net web to display Google analytic data. I am successfully able to get access token using oauth2.0. Using access token I am also get account information.
Here I want to get Google analytic data using access token. Please share link with me to get data using access token.
I have seen following code
http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/Analytics_DataFeed_Sample/dataFeed.cs
But don't want to use it because here I have to pass user name and password:
private const String CLIENT_USERNAME = "INSERT_LOGIN_EMAIL_HERE";
private const String CLIENT_PASS = "INSERT_PASSWORD_HERE";
Let me know any way to get analytic data using access token.
After long work will get success.....
Here is Oauth playground made by Google developer from you can test your data
https://code.google.com/oauthplayground/
I just Oauth 2.0 for retrieve access token information after that I am using following URL for getting analytic information.
https://developers.google.com/analytics/devguides/reporting/core/v2/gdataReferenceDataFeed
you need to pass access token with your URL ie :
https://www.googleapis.com/analytics/v2.4/data?ids=ga:12345&metrics=ga:visitors,ga:bounces&start-date=2012-07-01&end-date=2012-07-25&access_token=ya29.AHES6ZTzNR6n6FVcmY8uar6izjP9UGeHYNO5nUR7yU2bBqM
Best of luck Enjoy coding..
You can try with following code
string ClientId = "CLIENTID"
string ClientSecret = "CLIENTSECRET"
var Client = new NativeApplicationClient(GoogleAuthenticationServer.Description, ClientId, ClientSecret);
var Auth = new OAuth2Authenticator<NativeApplicationClient>(Client, Authenticate);
var Service = new AnalyticsService(Auth);
var Request = Service.Data.Ga.Get("profileID", StartDate, EndDate, "Matrix");
Request.MaxResults = 1000;
Request.Dimensions = "Dimensions";
var Result = Request.Fetch();