Use the Beta endpoint in the Graph Toolkit in SharePoint spfx - sharepoint

I want to fetch data from Graph from the new beta versions, specifically the user profiles.
When specifying the following code
let provider = new SharePointProvider(this.context);
provider.graph = BetaGraph.fromGraph(provider.graph);
Providers.globalProvider = provider;
I get the following error in the WebPart:
TypeError: Cannot read property 'client' of undefined at Function.fromGraph
Any advise? Do I need to specify the graph context object to connect to the beta endpoint somehow?

#Frank-Ove Kristiansen,
You can set the version on a specific request by using the version
Providers.globalProvider.graph.client.api('/users').version('beta').get().then(v => {
console.log(v);
});
And in mgt-get, it has a Version parameter:
<mgt-get resource="/me" version="beta"
//////////////////////////////
Update:
I found the reason. . BetaGraph.fromGraph will access Graph.client and use it to initialize a new betagraph instance. However onInit() is an asynchronous method, at that time, client or graph is not available, thus it will prompt "undefined" error.
We can put provider.graph = BetaGraph.fromGraph(provider.graph); in another method. for example, i put it in the constructor of my react componment:
Then it works fine, all requests are using beta endpoints
BR

Related

Google Analytics API service object - no management attribute

I am trying to set up an application that uses the Google Analytics API. I have all the authorization steps working correctly and can pull all the data as expected. However, at the moment, it is working because I have hardcoded my own view ID into the queries to the API. E.g:
response = analytics.reports().batchGet(
body={
"reportRequests":
[
{
"viewId": "ga:12345678",
...
From what I understand, what I need to do is before I start querying the data, is use the service object to first get a view Id (or list of View Ids), then use that in the data queries. I have been attempting to do just that and have been failing miserably. Basically, I have the following (just to get the first step of a list of accounts):
credentials = client.OAuth2Credentials.from_json(session['credentials'])
http = credentials.authorize(httplib2.Http())
analytics = build('analytics', 'v4', http=http) #create the service object
data = analytics.management().accounts().list().execute()
The error I am getting is 'Resource' object has no attribute 'management'. What am I missing here??
Ok, so for those who come across this question, the issue seemed to be that, as of the time of writing, version 4 of the API does not have the management features. What I/we did instead was build a second service to get the account details using version 3:
service = build('analytics', 'v3', http=http)
accounts = service.management().accounts().list().execute()
That seemed to do the trick, although there was some additional fiddling required in order to get the view ID(s). However, once you have the object, it is just a matter of manipulating the object as needed.

Getting extension properties using Azure AD B2C Graph API does not work

I am attempting to discover which extension properties I have available to my application. I originally followed this guide to get the extension attributes:
https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-devquickstarts-graph-dotnet/#use-custom-attributes
But that just returns the following JSON:
{
"odata.metadata": "https://graph.windows.net/screenmediatestb2c.onmicrosoft.com/$metadata#directoryObjects/Microsoft.DirectoryServices.ExtensionProperty",
"value": []
}
I have also attempted to do this with regular HTTP requests using Postman, but with the exact same result. I can authenticate and load applications, users, groups etc. But it doesn't return any of my custom attributes, of which I have 2.
The endpoint I am using is:
https://graph.windows.net/[tenant]/applications/[application object ID]/extensionProperties?api-version=1.6
Does anyone have any idea what I am doing wrong?
I just noticed a disclaimer at the bottom of this page https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-reference-custom-attr/. Looks like this might be our problem.
There is a known limitation of custom attributes. It is only created
the first time it is used in any policy, and not when you add it to
the list of User attributes.
There is a bug in the accompanying GitHub repo for the tutorial at:
https://azure.microsoft.com/en-us/documentation/articles/active-directory-b2c-devquickstarts-graph-dotnet/#use-custom-attributes
Un-bust your balls by changing Program.GetB2CExtensionApplication(...) to:
private static void GetB2CExtensionApplication(string[] args)
{
object formatted = JsonConvert.DeserializeObject(client.
GetApplications("$filter=startswith(displayName, 'b2c-extensions-app')").Result);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine(JsonConvert.SerializeObject(formatted, Formatting.Indented));
}
Instead of checking if the displayName equals 'b2c-extensions-app' it checks if it starts with 'b2c-extensions-app'. They have changed the name of the application in later versions of Azure AD B2C.
When you use the returned ID to get your extensions you will see that the Custom Attribute Name is prefixed with a Guid, and that's why we're been having trouble accessing it:
Eg. extension_10ecdccd92c446829a399e68ed758978_MyCustomAttribute
The correct GET URL for the Get-B2C-Application should be:
GET https://graph.windows.net/{Tenant}/applications?api-version=1.6&$filter=startswith(displayName,'b2c-extensions-app')
And the GET URL for the Extensions Properties (Custom Atttributes) should be:
GET https://graph.windows.net/{Tenant}/applications/{ObjectID}/extensionProperties?api-version=1.6
It's possible to get the attributes via LINQ:
string selectClause = "GivenName,Surname,Id,Mail"
+ ",extension_{ExtensionPropertyPrefixGUID}_myAttribute1"
+ ",extension_{ExtensionPropertyPrefixGUID}_myAttribute2";
var result = await _graphClient.Users
.Request()
.Select(selectClause)
.GetAsync();
The extension attributes will then be accessible via the AdditionalData
foreach (User user in result.CurrentPage)
{
string attribute1Value = (string)user.AdditionalData["extension_{ExtensionPropertyPrefixGUID}_myAttribute1";
}

NULL Reference when trying to get NameIdentifier Claim

I modified the TodoSPA sample application on github to be a 1.0.0-rc1-update1 application since that is the platform we are developing with. I had to make changes to Startup but left the client code as is. The sample uses the OAuth2 implicit flow with the ADAL client library. When I click on the TodoList link, I authenticate against the authentication server and the client calls the Get method in the TodoListController class. So far, so good. The Get method does the following.
string owner = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
IEnumerable<Todo> currentUserToDos = db.Todoes.Where(a => a.Owner == owner);
FindFirst throws a null reference exception. Why don't I get a NameIdentifer claim? If I get all of the claims using ClaimsPrincipal.Current.Claims, I don’t see as many as I would expect. (Results from Visual Studio 2015 Watch Window.)
Results View Expanding the Results View will enumerate the IEnumerable
[0] {http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name: } System.Security.Claims.Claim
[1] {http://schemas.microsoft.com/ws/2008/06/identity/claims/role: } System.Security.Claims.Claim

NotSupported result when LaunchQuerySupportType is UriForResults

I have a UWP app in which I've defined a custom protocol. I'm currently launching that app via another app using the LaunchUriForResultsAsync and receiving a the expected response without a problem:
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName = TARGET_PACKAGE;
var launchResults = await Launcher.LaunchUriForResultsAsync(new Uri($"myprotocol:?b={cids}"), options);
However, when I want to query to see if I have an app installed that can handle myprotocol: I'm not getting the result I expect.
The first method, using LaunchQuerySupportType.Uri returns Supported as expected:
var queryResult = await Launcher.QueryUriSupportAsync(new Uri("myprotocol:"), LaunchQuerySupportType.Uri, TARGET_PACKAGE);
When using LaunchQuerySupportType.UriForResults I get NotSupported returned.
var queryResult = await Launcher.QueryUriSupportAsync(new Uri("myprotocol:"), LaunchQuerySupportType.UriForResults, TARGET_PACKAGE);
Is there a flag I'm missing in the manifest of my app that implements the custom protocol? What am I missing here?
(see QueryUriSupportAsync)
The answer typically appears ONLY after posting the question :p
There is a ReturnResults attribute that is not exposed in the GUI for the Package.appxmanifest when setting up the protocol
The ReturnResults attribute in the protocol extension accepts one of these values:
optional—The app can be launched for results by using the LaunchUriForResultsAsync method, or not for results by using LaunchUriAsync. When you use optional, the launched app must determine whether it was launched for results. It can do that by checking the OnActivated event argument. If the argument's IActivatedEventArgs.Kind property returns ActivationKind.ProtocolForResults, or if the type of the event argument is ProtocolActivatedEventArgs, the app was launched via LaunchUriForResultsAsync.
always—The app can be launched only for results; that is, it can respond only to LaunchUriForResultsAsync.
none—The app cannot be launched for results; it can respond only to LaunchUriAsync.
(see How to launch an app for results)

Detail of list without user authentication

I'm trying to get details of Foursquare list by PHP library:
$foursquare = new FoursquareAPI($key,$secret);
$list = $foursquare->GetPublic('lists/'.$listId);
But everytime gets this error:
string(7672) "{"meta":{"code":200,"errorType":"deprecated","errorDetail":"Please provide an API version to avoid future errors.See https:\/\/developer.foursquare.co ... "
When I debug it, library calls this URL: https://api.foursquare.com/v2/lists/ with these params: Array ( [client_id] => <client_id> [client_secret] => <client_secret> )
But when I try this API method in Foursquare API Explorer I see that, this URL is calling: OAuth token automatically added. https://api.foursquare.com/v2/lists/<list_id>?oauth_token=<token>&v=20111205.
In lists doc is Requires Acting User: No, so I'm confused. Is it possible to call this function without authenticating user?
It would be nice, because I want to add places from my list (favourite restaurants) to my page on Google map in Contacts. It would be useful for our clients.
The error you are seeing is unrelated to the list endpoint you are requesting or the state of authentication. It is a warning that the library you are using is currently not following versioning best practice for Foursquare. You can read more about it here.
As for the list there should be a response object at the same level as the meta object.

Resources