NULL Reference when trying to get NameIdentifier Claim - azure

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

Related

Use the Beta endpoint in the Graph Toolkit in SharePoint spfx

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

Google API SignIn HostedDomain cleanup problem

We implement the Sign-In on iOS using the Google API in our project. Customers must have a possibility to select the HostedDomain to limit the allowed account pull to the single domain.
SignIn.SharedInstance.HostedDomain = "domainName.com";
works perfectly.
The problem is when we want to Logout the user and log in it back with unrestricted HostedDomain
SignIn.SharedInstance.HostedDomain == null; // <-Default Value
When I try to set it to
SignIn.SharedInstance.HostedDomain=string.empty;
I filter everything.
When I try to set it to null
SignIn.SharedInstance.HostedDomain=null;
I get the exception.
Calling:
SignIn.SharedInstance.Dispose();
doesn't help.
The question is: How is possible to reset the HostedDomain filtering to the initial stage - allow everything without of the app restart.
Our implementation based on Xamarin iOS native, but we see the same problem in Swift or Objective-C.
The wrapper for the Gooogle SDK we use:
Xamarin.Google.iOS.SignIn

How to use sharepoint online search api as app-only

I'm trying to use the sharepoint online search api (/_api/search) from an application. Adding it from the Azure portal I see the search is only in the "delegated permissions" section. When I ran it in testing with the user login and approve it it works well.
Since I don't want to need a user to login for this, I found this article
https://blogs.msdn.microsoft.com/vesku/2016/03/07/using-add-in-only-app-only-permissions-with-search-queries-in-sharepoint-online/
That made me believe it would be possible to use search as an app-only and not as a user. I followed all the steps, created the app through appregnew.aspx , I also added another permission via appinv.aspx so the permissions I asked for are the following :
<AppPermissionRequests AllowAppOnlyPolicy="true">
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="FullControl" />
<AppPermissionRequest Scope="http://sharepoint/search" Right="QueryAsUserIgnoreAppPrincipal" />
</AppPermissionRequests>
I'm testing using ADAL JAVA SDK as follows:
Future<AuthenticationResult> future = context.acquireToken(
resource, new ClientCredential(clientId,
clientSecret), null);
where resource is xxxxxx.sharepoint.com and I'm later using this token as the bearer token.
But when I'm trying to test this I get the following error:
2018-08-05 11:03:22 WARN ODataUtils:120 - Failed to get a successful response for uri [https://XXXXXX.sharepoint.com/_api/search], reason [{"error_description":"The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework SDK documentation and inspect the server trace logs."}];
Since this is sharepoint online I don't have a server and I'm not using the .NET framework so what other way do I have to debug this? or other idea what I'm doing wrong here?
Any help would be greatly appreciated.
Maybe you can use the Java to call SharePoint Search Api and show the result(But we need to spend many time to research on this, there are many uncertainties.)
The best choice for you is to use the VisualStudio to test the SharePoint Addin. Microsoft provide more support on it and you can use the ready-made template.
You can use the wide range of search-related APIs that SharePoint offers for search add-ins:
.NET client object model (CSOM)
Key libs:
Microsoft.SharePoint.Client.Search.dll ;
Silverlight CSOM
Key libs:
Microsoft.SharePoint.Client.Search.Silverlight.dll ;
ECMAScript (JavaScript, JScript) object model (JSOM)
Key libs:
SP.search.js ;
Search REST API
http://server/_api/search/query
Some demo code:
Client-side Object Model (CSOM)
C#
using (ClientContext clientContext = new ClientContext("http://localhost"))
{
KeywordQuery keywordQuery = new KeywordQuery(clientContext);
keywordQuery.QueryText = "*";
SearchExecutor searchExecutor = new SearchExecutor(clientContext);
ClientResult<ResultTableCollection> results =
searchExecutor.ExecuteQuery(keywordQuery);
clientContext.ExecuteQuery();
}
JavaScript Object Model (JSOM)
var keywordQuery = new
Microsoft.SharePoint.Client.Search.Query.KeywordQuery(context);
keywordQuery.set_queryText('SharePoint');
var searchExecutor = new Microsoft.SharePoint.Client.Search.Query.SearchExecutor(context);
results = searchExecutor.executeQuery(keywordQuery);
context.executeQueryAsync(onQuerySuccess, onQueryFail);
REST
HTTP GET request
HTML
http://mylocalhost/_api/search/query?querytext='SharePoint'
HTTP POST request
HTML
{
'__metadata' : {'type' : 'Microsoft.Office.Server.Search.REST.SearchRequest'},
'Querytext' : 'SharePoint'
}
Then set the permissions by VisualStudio and "Napa" Office 365 Development Tools
More information on Search add in:
https://learn.microsoft.com/en-us/sharepoint/dev/general-development/search-add-ins-in-sharepoint

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";
}

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