My UWP VPN app add to username another symbols - c#

I create vpn profile from my UWP app
public async void connect()
{
var config = #"
<VPNProfile>
<ProfileName>testConnection</ProfileName>
<NativeProfile>
<Servers>***.**.**.***</Servers>
<RoutingPolicyType>SplitTunnel</RoutingPolicyType>
<NativeProtocolType>IKEv2</NativeProtocolType>
<Authentication>
<UserMethod>Eap</UserMethod>
<Eap>
<Configuration>
<EapHostConfig xmlns=""http://www.microsoft.com/provisioning/EapHostConfig"">
<EapMethod>
<Type xmlns = ""microsoft.com/provisioning/EapCommon"">26</Type>
<VendorId xmlns = ""microsoft.com/provisioning/EapCommon"">0</VendorId>
<VendorType xmlns = ""microsoft.com/provisioning/EapCommon"">0</VendorType>
<AuthorId xmlns = "microsoft.com/provisioning/EapCommon"">0</AuthorId>
</EapMethod>
<Config xmlns = ""microsoft.com/provisioning/EapHostConfig"">
<Eap xmlns = "".microsoft.com/provisioning/BaseEapConnectionPropertiesV1"">
<Type>26</Type>
<EapType xmlns = ""microsoft.com/provisioning/MsChapV2ConnectionPropertiesV1"">
<UseWinLogonCredentials>false</UseWinLogonCredentials>
</EapType>
</Eap>
</Config>
</EapHostConfig>
</Configuration>
</Eap>
</Authentication>
</NativeProfile>
<RequireVpnClientAppUI>true</RequireVpnClientAppUI>
<RememberCredentials>true</RememberCredentials>
</VPNProfile>";
VpnManagementErrorStatus profileStatus = await windowsVpnManager.AddProfileFromXmlAsync(config);
var profiles = await windowsVpnManager.GetProfilesAsync();
var profile = profiles.First(p => p.ProfileName == "testProfile") as VpnNativeProfile;
var connectionStatus = await windowsVpnManager.ConnectProfileWithPasswordCredentialAsync(profile, new PasswordCredential { UserName = "test", Password = "test123" });
Debug.Print($"Connection status -> {connectionStatus}");
}
If I try to connect to a server, I see at server logs received EAP identity '?\test'.
My username credential transform from "test" to "?\test"
Sorry for my English :)

This question has already answered by Peter Smith on Microsoft Q&A here: UWP VPN app add to username another symbols
I will post a summary here so others who meet the same question could know the reason.
Answer from Perter:
The code adds the "?" because that's what the Microsoft RRAS server is expecting to see. The Windows IKEv2 was designed to work as part of the entire Domain solution. Each user is part of some "Domain" -- in some companies, everyone is in one domain; in others people get put into different domains.
The VPN developers think that because you're providing a user name ("test") without a domain name, a dummy domain name ("?") is added along with the needed backslash.

Related

Determine if a given url (from a string) is from my domain or not

I'm trying to check from c# code if a given url is from my domain or not, in order to add the "nofollow" and "target _Blank" attributes for external links.
When i talk about external links i refer to any link outside my domain.
By default it does not have that attributes. I tried a lot of stuff, basically this is the part i need to fix:
public void PrepareLink(HtmlTag tag)
{
string url = tag.attributes["href"];
if (PrepareLink != null)
{
if (it is from an external site???)
{
tag.attributes["rel"] = "nofollow";
tag.attributes["target"] = "_blank";
}
}
Edit:
things i've tried:
string dominioLink = new Uri(url).Host.ToLower();
if (!dominioLink.Contains(myDomainURL))
{
tag.attributes["rel"] = "nofollow";
tag.attributes["target"] = "_blank";
}
Which has the issue that dont take in mind subdomains
i.e. if a link created is http://www.mydomain.com.anotherfakedomain.com, it will return true and work well.
I've looked in every Uri property but didn't seem to contains the base domain.
I'm currently using .NET Core 2.0.
thankS! please if you need any other data just let me know.
You can use the Uri.Host property to obtain the domain from a URL string, then compare it to your own. I suggest using a case-insensitive match.
var url = tag.attributes["href"];
var uri = new Uri(url);
var match = uri.Host.Equals(myDomain, StringComparison.InvariantCultureIgnoreCase)

Moving files with Google Drive API v3

Im trying to move a file from one folder to another using the Google Drive API v3. I found documentation how to this here. I used the .NET sample code from the documentation page and created a method that looks like this:
public ActionResult MoveFile(string fileToMove, string destination)
{
DriveService service = new DriveService(new BaseClientService.Initializer
{
HttpClientInitializer = <USER CREDENTIAL>,
ApplicationName = "APPNAME"
});
var searchFiles = service.Files.List();
searchFiles.Corpus = FilesResource.ListRequest.CorpusEnum.User;
searchFiles.Q = "name = '" + fileToMove + "'";
searchFiles.Fields = "files(*)";
string fileToMoveId = searchFiles.Execute().Files[0].Id;
searchFiles.Q = "name = '" + destination + "'";
string destinationId = searchFiles.Execute().Files[0].Id;
//Code used from documentation
// Retrieve the existing parents to remove
var getRequest = service.Files.Get(fileToMoveId);
getRequest.Fields = "parents";
var file = getRequest.Execute();
var previousParents = String.Join(",", file.Parents);
// Move the file to the new folder
var updateRequest = service.Files.Update(file, fileToMoveId);
updateRequest.Fields = "id, parents";
updateRequest.AddParents = destinationId;
updateRequest.RemoveParents = previousParents;
file = updateRequest.Execute();
return RedirectToAction("Files", new {folderId = destinationId});
}
When I execute this code I get the following error:
The parents field is not directly writable in update requests. Use the
addParents and removeParents parameters instead.
The error doesn't really makes sense to me because this code sample came from the documentation page itself. I can't figure out what other paramters they mean. What addParents and removeParents parameters do they mean? Are updateRequest.AddParents and updateRequest.RemoveParents not the right parameters?
Ok here is the problem.
var updateRequest = service.Files.Update(file, fileToMoveId);
The method is requiring that you send a body of a file to be updated. This normally makes sense as any changes you want to make you can add to the body.
Now the problem you are having is that you got your file from a file.get. Which is totally normal. This is how you should be doing it. THe problem is there are some fields in that file that you cant update. So by sending the full file the API is rejecting your update. If you check Files: update under Request body you will see which fiends are updateable.
Issue:
Now this is either a problem with the client library or the API I am going to have to track down a few people at Google to see which is the case.
Fix:
I did some testing and sending an empty file object as the body works just fine. The file is moved.
var updateRequest = service.Files.Update(new Google.Apis.Drive.v3.Data.File(), fileToMove.Id);
updateRequest.AddParents = directoryToMove.Id;
updateRequest.RemoveParents = fileToMove.Parents[0];
var movedFile = updateRequest.Execute();
This method works well when working in your own drive, but not in a team drive where a file (folder) can only have 1 parent strictly. I do not have the solution in a team drive

Cache player with GameSparks and Unity

I am new to gamesparks, but so far I have set up a login/register function, which works like it should, but... How do I ensure that the user don't have to login next time he or she opens the app?
I found this in which I read that I can just run this:
GameSparkssApi.isAuthenticated().
First off all, in all other tutorials it states that it should be: GameSparks.Api.xxxx. Even when trying this I do not find isAuthenticated() anywhere.
GameSparks.Api.isAuthenticated();
I am hoping that someone can cast some light on this.
You can use Device Authentication for this purpose. This method of auth sets an access token for the device you are on. This token is stored and the client and gotten in the request. these requests are structured like so:
new GameSparks.Api.Requests.DeviceAuthenticationRequest()
.SetDeviceId(deviceId)
.SetDeviceModel(deviceModel)
.SetDeviceName(deviceName)
.SetDeviceOS(deviceOS)
.SetDeviceType(deviceType)
.SetDisplayName(displayName)
.SetOperatingSystem(operatingSystem)
.SetSegments(segments)
.Send((response) => {
string authToken = response.AuthToken;
string displayName = response.DisplayName;
bool? newPlayer = response.NewPlayer;
GSData scriptData = response.ScriptData;
var switchSummary = response.SwitchSummary;
string userId = response.UserId;
});
You can find more on this method in our documentation: https://api.gamesparks.net/#deviceauthenticationrequest
Regards Patrick, GameSparks.

EPiServer Community member Avatar error

I am developing EPiServer CMS 7 MVC site with Community. I am trying to get and display member Avatar (Avatar exist physically in Contributed files folder). Here is my code:
var user = CurrentUser;
var image = user.GetPortraitUri(ImageSize.Huge).ToString();
variable image gets value:
http://localhost:18000/EPiServerCommunity/Modules/ImageGallery/ImageHandler.ashx?imageId=7&thumbnailId=10
But on View I see only image icon (like when can't upload or display image). When I am trying to open this image link in new tab its redirect me to EPiServer login page. I cant understand why it redirect me to login page if user is authorized. Any ideas?
Additional information:
I installed EPiServer Relate site using Deployment center. There is the same way of getting user Avatar on EditProfile user control or on MyPage. And when I am trying to open image in new tab using getted Url I see it. I think there can be some permissions in Web.config file , but I dont know ....
Add new information (11/10/2014). The problem is in section
I mean in section of EPiServerCommunity section. When I changed to deny in installed previously EpiServer Relate site than I am getting login page when I am trying to open image. In my web.config file I changed all deny to allow, but still I am getting login page when I am trying to open image by url. I guess Episerver doesnt see this section in web.config file.
Add new information (11/11/2014). I added one more role "Everyone" to of section. I see that when I am trying to open localhost:18000\episerver it skip login page. I added the same role "Everyone" to EpiServerCommunity section. Now it looks:
<location path="EPiServerCommunity">
<system.web>
<pages enableViewState="true" />
<authorization>
<allow roles="CommunityAdmins,CommunityModerators,Administrators,Everyone" />
<allow users="*" />
</authorization>
</system.web>
But I am still getting login page when I am trying to open image by url :(
P.S. This question I posted in EPiServer World, but I hope I will get answer here more quickly.
Resolved my problem. EPiServer skips permitions in location section. I created class CommunitySecurityModule with events DefaultSecurity_CreatedUser and MyPageHandler_Register where I set Owner to ImageGallery and other AccessRights for newsfeed and etc. Now when I had registered user and added it to System
newUser = CommunitySystem.CurrentContext.DefaultSecurity.AddUser(newUser);
it calls MyPageHandler_Register and sets all rights:
var user = e.Object as IUser;
if (user != null)
{
var myPage = MyPageHandler.Instance.GetMyPage(user);
if (myPage != null && myPage.ImageGallery != null)
{
foreach (var imageGallery in myPage.ImageGallery.Children)
{
var imageGalleryClone = imageGallery.CreateWritableClone() as ImageGallery;
imageGalleryClone.SetOwner(user);
ImageGalleryHandler.Instance.UpdateImageGallery(imageGalleryClone);
}
}
}
Implementation of SetOwner method below:
public static void SetOwner(this ImageGallery imageGallery, IUser owner)
{
imageGallery.SetAttributeValue("Owner", owner);
}
Implementation of DefaultSecurity_CreatedUser:
private void DefaultSecurity_CreatedUser(ISecurityHandler sender, ICreateUserEventArgs args)
{
// Add user to the community members group
var group = CommunityMembersGroup;
var addedUser = args.User;
addedUser = (IUser)addedUser.CreateWritableClone();
addedUser.Groups.Add(group);
// Update the user
CommunitySystem.CurrentContext.DefaultSecurity.UpdateUser(addedUser);
// Set access rights to the newly created user
// Access right for anonymous users
var anonAccessRights = new ReadModifyRemoveAccessRights
{
Read = true,
};
EntitySecurityHandler.Instance.SetAccessRights(addedUser, AnonymousGroup, anonAccessRights);
// Access right for community members
var communityMembersAccessRights = new ReadModifyRemoveAccessRights
{
Read = true,
};
EntitySecurityHandler.Instance.SetAccessRights(addedUser, group, communityMembersAccessRights);
// Access rights for administrators
var adminAccessRights = new ReadModifyRemoveAccessRights
{
Read = true,
Modify = true,
Remove = true
};
EntitySecurityHandler.Instance.SetAccessRights(addedUser, AdministratorsGroup, adminAccessRights);
// Access rights for the added user
var userAccessRights = new ReadModifyRemoveAccessRights
{
Read = true,
Modify = true,
Remove = true
};
EntitySecurityHandler.Instance.SetAccessRights(addedUser, addedUser, userAccessRights);
// Access rights for moderator
var moderatorAccessRights = new ReadModifyRemoveAccessRights
{
Read = true,
Modify = true,
Remove = true
};
EntitySecurityHandler.Instance.SetAccessRights(addedUser, ModeratorsGroup, moderatorAccessRights);
}
Note: Before that you should create Attribute "Owner" of type IUser for type ImageGallery in admin panel.

Get media url including server part

Is it possible to get url with MediaManager.GetMediaUrl that always includes the server part?
Just to bump this up, in Sitecore 7 the AlwaysIncludeServerUrl option is also included in MediaUrlOptions (I don't know since which version of Sitecore)
Like this:
MediaUrlOptions muo = new MediaUrlOptions();
muo.AlwaysIncludeServerUrl = true;
String url = MediaManager.GetMediaUrl((MediaItem)item, muo);
I've discovered that the following will work for producing fully qualified urls for media items:
public static string GetMediaUrlWithServer(MediaItem mediaItem, Item item = null)
{
item = item ?? Sitecore.Context.Item;
var options = new UrlOptions {AlwaysIncludeServerUrl = true, AddAspxExtension = false};
var itemUrl = LinkManager.GetItemUrl(item, options);
var mediaOptions = new MediaUrlOptions {AbsolutePath = true};
var mediaUrl = MediaManager.GetMediaUrl(mediaItem, mediaOptions);
return itemUrl + mediaUrl;
}
The urls produced will be relative to item so you may want to supply a reference to your Home item instead of Sitecore.Context.Item
I just answered a similar question on Stack Overflow recently. I believe the answer applies to yours as well.
Short summary: there is no configuration to do this, you need to override some of the built-in methods to do this. See the above link for the exact details.
Yes, you can do that!
The correct way of setting this parameter is specifying within config file at linkManager section, where you have this anŠ² the rest of settings regarding how you URLs will be resolved. Here's the whole section, you're interested in alwaysIncludeServerUrl parameter:
<linkManager defaultProvider="sitecore">
<providers>
<clear />
<add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel"
alwaysIncludeServerUrl="true"
addAspxExtension="true"
encodeNames="true"
languageEmbedding="asNeeded"
languageLocation="filePath"
shortenUrls="true"
useDisplayName="false" />
</providers>
</linkManager>

Categories