How to get Google User Information from Token - api

I have an app that uses Google Authentication to sign in. After getting the user id token, I need to get this information from the user's profile:
Email
FullName
Profile Picture.
I've seen an example using this endpoint:
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=ID
But this endpoint is not worked for me.
How can I get these profile information?

Can you try this URL : https://www.googleapis.com/oauth2/v3/userinfo?access_token=access_token.
This URL will return following Information
public class GoogleAuthClass
{
public string email { get; set; }
public bool email_verified { get; set; }
public string name { get; set; }
public string picture { get; set; }
}

You could use the Plugin.GoogleClient nuget and follow this Tutorial.
You will be able to access all the properties from the Google API and manage them as you require.
NOTE: This tutorial uses Firebase Auth.
More information can be seen at:
https://www.xamboy.com/2019/11/19/social-media-authentication-google-login-in-xamarin-forms/

Related

Edit Account user and role .Net core Identity

I am using .Net Core Identity 5, I did add Role for the user when registering the account. I want when I Edit the user information of that account, I can change their Role in the system.
I am working in Repo, how can I work with it most effectively?
Viewmodel
public class UserRoleViewModel
{
public string UserId { get; set; }
public string FullName { get; set; }
public string Email { get; set; }
public string Role { get; set; }
}

API endpoint that depends of the Authenticated user

I have the following entities:
public class Company {
public Int32 CompanyId { get; set; }
public String Name { get; set; }
}
public class Project {
public Int32 ProjectId { get; set; }
public String Name { get; set; }
public virtual Company { get; set; }
}
public class ProjectUser {
public Int32 UserId { get; set; }
public String ProjectId { get; set; }
}
public class User {
public Int32 UserId { get; set; }
public String Name { get; set; }
}
I need to create an Api endpoint to get a Company's Projects:
companies/{companyId}/projects
This url makes sense but returning projects should be restricted to:
Projects, in provided company, where current authenticated user is associated (ProjectUser);
OR
All projects, in provided company, if current authenticated user is system admin.
Question
So this request depends on the authenticated user ...
Should I send the UserId in the request and then check its permissions in the API?
If yes, how would the url, e.g. companies/{companyId}/projects, become?
Or should I simply get the authenticated User and checks its permissions in the API without sending the UserId in the Request?
The latter. Your request should be authorized, most likely via sending the Authorization header with a previously obtained access token. You should not nor do you need to send the user id along with the request. That would be obtained via the user principal, specifically via the NameIdentifier claim. As for your resource-level authorization, you'll use the user id obtained from the principal to ensure that the authenticated user has access to said resource, most normally via a foreign key on the resource itself. The docs have a more extensive guide.

Piranha CMS localisation

How can I localize the excelent Piranha Headless CMS solution?
I want to be able to allow the user to select a language and display content in function of that selection. I just want to display two sets of pages, no globalization.
Kind regsrds,
Karel
Since the CMS itself isn't multi-lingual at this point, your best option would be to add two different site, one for each language. In the hostnames field of your site your could for example set it up like:
mydomain.com // For the default site
mydomain.com/lang // For the translated site
The downside of this would of course be having to manage two different sitemaps.
Another option would be to create a TranslationRegion where you can translate all of the base fields of the page, for example:
public class PageLocalization {
[Field]
public StringField Title { get; set; }
[Field]
public StringField NavigationTitle { get; set; }
[Field]
public StringField Keywords { get; set; }
[Field]
public TextField Description { get; set; }
}
You could also create a reusable region for HTML-content, like so:
public class HtmlLocalization {
[Field]
public HtmlField Body { get; set; }
[Field]
public HtmlField TranslatedBody { get; set; }
}
And then use these when building your page type.
[PageType(Title = "My Page")]
public class MyPage : Page<MyPage> {
[Region]
public PageLocalization PageLocalization { get; set; }
[Region]
public HtmlLocalization MainContent { get; set; }
}
With this solution you would only need one site and one sitemap, but views will have to handle which fields to use when rendering the site depending on the choosen language.
Like I mentioned earlier, there's really no built in features in Piranha CMS for multi-lingual support, but it might be added in the future. There is a feature request for it at GitHub but it's nothing that's planned for development in the near future.
Regards

How to get the email of the current user in Silverlight 4 Business Application?

I am using a custom MembershipProvider (using EF, rather than Sql) with a SL4 business application.
The default implementation of the MembershipUser class has an e-mail address property, however the User object defined by the SL4 Business Application template (inheriting from UserBase )does not give you access to the Email property.
Moreover when the AuthenticationService (inheriting from AuthenticationBase<User>) does not even attempt to read the user's e-mail.
Is there a way to access the Email property of the MembershipUser(server side)/User(client side) by using the AuthenticationService, or do I have to create my own routines to return the right properties of the user?
Thanks,
Martin
You can create your own User class as long as you implement IUser.
public class User : IUser
{
public int Id { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public string Email { get; set; }
#region Implementation of IUser
public string Name { get; set; }
public IEnumerable<string> Roles { get; set; }
#endregion
}
You can modify the AuthenticationService to Implement IAuthentication<User> and implement Login. As part of your implemented Login process you can populate the User.Email.
public class AuthenticationService : DomainService, IAuthentication<User>
{
public User Login(string userName, string password, bool isPersistent, string customData)
{
//can populate User.Email on successful login.
}
}

Rolling my own CMS with the WCF, what should my contract be?

I'm looking to create a solution for a asp.net mvc app that displays unstructured course descriptions that have been scraped from around the web. The web server will be on a web hosting company while the description db will be on a private network, so I'd like to pass the description to the mvc app through a WCF service. For the body of the description do I just want to use a string property...
public class CourseDescription {
// data fields
public string CourseTitle { get; set; }
public int Days { get; set; }
public List<DateTime> UpcomingDates { get; set; }
// html properties
public string Keywords { get; set;}
public string HtmlDescription { get; set; }
}
... or is there a better way?
If it is unstructured text, a string is fine.