Getting the current user in sifefinity 4.4 - sitefinity-4

How do I pro-grammatically get the current user that is logged into sitefinity 4.4?
Thanks,
Ann

Whenever you are in the context of a Sitefinity page, you can do this:
var uId = Telerik.Sitefinity.Security.SecurityManager.GetCurrentUserId();
It's just a static method on the SecurityManager class.

Related

Trouble populating an input with an App Properties value

Working on my first Xamarin Forms app. I put this in my App's OnStart() method:
Application.Current.Properties["Email"] = "gern#blanston.org";
That should set the value as soon as the Application starts, right?
Then I created a Login content page with an EmailAddress entry. In the page initialization, I've got this:
if (Application.Current.Properties.ContainsKey("Email"))
{
EmailAddress.Text = Application.Current.Properties["Email"] as string;
}
When I run the app, the EmailAddress Entry element is not populated.
What am I doing wrong?
OnStart command is called after App constructor and you probably creating login page in App constructor and checking in login page constructor but OnStart is not called yet. Set it before you created login/main page
Application.Current.Properties["Email"] = "gern#blanston.org";
var navPage = new MainPage();
It should work.
Here is the Documentation.
You can try to use SavePropertiesAsync
The Properties dictionary is saved to the device automatically. Data added to the dictionary will be available when the application returns from the background or even after it is restarted.
Xamarin.Forms 1.4 introduced an additional method on the Application class - SavePropertiesAsync() - which can be called to proactively persist the Properties dictionary. This is to allow you to save properties after important updates rather than risk them not getting serialized out due to a crash or being killed by the OS.

Google Drive SDK 1.8.1 RedirectURL

Is there any way to provide RedirectURL then using GoogleWebAuthorizationBroker?
Here is the sample code in C#:
Task<UserCredential> credential = GoogleWebAuthorizationBroker.AuthorizeAsync(secrets, scopes, GoogleDataStore.User, cancellationToken, dataStore);
Or we have to use different approach?
I have an "installed application" that runs on a user's desktop, not a website. By default, when I create an "installed application" project in the API console, the redirect URI seems to be set to local host by default.
What ends up happening is that after the authentication sequence the user gets redirected to localhost and receives a browser error. I would like to prevent this from happening by providing my own redirect URI: urn:ietf:wg:oauth:2.0:oob:auto
This seems to be possible using Python version of the Google Client API, but I find it difficult to find any reference to this with .NET.
Take a look in the implementation of PromptCodeReceiver, as you can see it contains the redirect uri.
You can implement your own ICodeReceiver with your prefer redirect uri, and call it from a WebBroker which should be similar to GoogleWebAuthorizationBroker.
I think it would be great to understand why can't you just use PrompotCodeReceiver or LocalServerCodeReceiver.
And be aware that we just released a new library last week, so you should update it to 1.9.0.
UPDATE (more details, Nov 25th 2014):
You can create your own ICodeReceiver. You will have to do the following:
* The code was never tested... sorry.
public class MyNewCodeReceiver : ICodeReceiver
{
public string RedirectUri
{
get { return YOU_REDIRECT_URI; }
}
public Task<AuthorizationCodeResponseUrl> ReceiveCodeAsync(
AuthorizationCodeRequestUrl url,
CancellationToken taskCancellationToken)
{
// YOUR CODE HERE FOR RECEIVING CODE FROM THE URL.
// TAKE A LOOK AT THE FOLLOWING:
// PromptCodeReceiver AND LocalServerCodeReceiver
// FOR EXAMPLES.
}
}
PromptCodeReceiver
and LocalServerCodeReceiver.
Then you will have to do the following
(instead of using the GoogleWebAuthorizationBroker.AuthorizeAsync method):
var initializer = new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = secrets,
Scopes = scopes,
DataStore = new FileDataStore("Google.Apis.Auth");
};
await new AuthorizationCodeInstalledApp(
new GoogleAuthorizationCodeFlow(initializer),
new MyNewCodeReceiver())
.AuthorizeAsync(user, taskCancellationToken);
In addition:
I'll be happy to understand further why you need to set a different redirect uri, so we will be able to improve the library accordingly.
When I create an installed application the current PromptCodeReceiver and LocalServerCodeReceiver work for me, so I'm not sure what's the problem with your code.

Setting roles by using GenericPrincipal instance

Recently I asked a question about how to use ajax calls to
authenticate user in asp.net mvc, and I got my answer.
But then is decided to use 'Roles' property of 'GenericPrincipal' class
so I changed my code as follow to contain 'Roles':
HttpContext.User = new System.Security.Principal.
GenericPrincipal(new System.Security.Principal.GenericIdentity(login.LoginName),
userRole);
In my site.master view, I check to see which kind of roles users
belongs to and I show appropriate menu, but when I watch
'HttpContext.Current.User.Identity' values during debugging,
I see m_roles=string[0] and 'IsInRole("Admin")' returns false.
How could it be fixed?
Try setting the current thread principle:
System.Threading.Thread.CurrentPrincipal = principal;
as is shown here:
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvcs/thread/5f9735a9-096b-47af-963d-e95130cad6b4

facebookredirect.axd in multi tenant application

I have one facebook mvc3 application that actually consists of several facebook apps.
Every app has it's own 'virtual path' (defined in the global.asax)
routes.MapRoute("Default", "{ns}/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional, ns = UrlParameter.Optional });
This means they have all use the same physical app, but have different paths: mydomain.com/facebookapp1, mydomain.com/facebookapp2, ...
The problem is that when I call for user authentication, the facebook page is called with a return url of mydomain.com/facebookredirect.axd. Facebook then decides this url is not part of that specific app, so it returns an error message.
So my question: where does the Facebook C# SDK get this facebookredirect.axd link from? I would like to change it to mydomain.com/facebookapp1/facebookredirect.axd. Does anyone know how to achieve this?
Thanks in advance!
May I suggest to separate your applications into multiple IIs applications?
app1.mydomain.com
app2.mydomain.com
etc..
Each app has its own host header.
That way they are isolated and aren't dependent on each other in terms when you want to deploy/update changes.

MVC3 + WIF - FederationResult missing "wctx"

I have an MVC3 app for which I want to implement claims support. My goal is as follows:
provide a SignIn link, which when clicked displays a popup window with username/password and Facebook/WindowsLive/Google etc. links
automatically redirect to my SignIn page when a protected controller is accessed e.g. /Order/Delete
I've set up the application and providers in AppFabricLabs.com and included the STS in my project. I've also created an implementation of IAuthorizationFilter so I can mark my controllers as [WifAuth] and successfully get the OnAuthorization method called. I've implemented the use-case where the visitor has not been authenticated like this:
private static void AuthenticateUser(AuthorizationContext context)
{
var fam = FederatedAuthentication.WSFederationAuthenticationModule;
var signIn = new SignInRequestMessage(new Uri(fam.Issuer), fam.Realm);
context.Result = new RedirectResult(signIn.WriteQueryString());
}
and successfully get AppFabricLabs page with my Identity Provider choices (haven't figured out how to customise that page). When I log in my returnUrl gets called so I land in a controller method /Home/FederationResult, however the form posted to me contains only wa and wresult fields but I need wctx to know where to send the user... I haven't been able to figure out why.
the wresult is an XML document that contains (amongst a bzillion other things) the name and e-mail address of the user logging in but sadly does not contain the url to which the user was headed.
have I failed to configure something or am I just off base? thoughts anyone?
e
Just specify a Context for the SignInRequestMessage:
signIn.Context = HttpContext.Current.Request.RawUrl;
The wctx parameter is included in every request/response and also part of the form posted finally to your site.

Resources