{"action":"created","issue":{"url":"https://api.github.com/repos/spring-guides/tut-spring-boot-oauth2/issues/8","repository_url":"https://api.github.com/repos/spring-guides/tut-spring-boot-oauth2","labels_url":"https://api.github.com/repos/spring-guides/tut-spring-boot-oauth2/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/spring-guides/tut-spring-boot-oauth2/issues/8/comments","events_url":"https://api.github.com/repos/spring-guides/tut-spring-boot-oauth2/issues/8/events","html_url":"https://github.com/spring-guides/tut-spring-boot-oauth2/issues/8","id":136022722,"number":8,"title":"How to Add a Local User Database","user":{"login":"houssemzaier","id":2019669,"avatar_url":"https://avatars.githubusercontent.com/u/2019669?v=3","gravatar_id":"","url":"https://api.github.com/users/houssemzaier","html_url":"https://github.com/houssemzaier","followers_url":"https://api.github.com/users/houssemzaier/followers","following_url":"https://api.github.com/users/houssemzaier/following{/other_user}","gists_url":"https://api.github.com/users/houssemzaier/gists{/gist_id}","starred_url":"https://api.github.com/users/houssemzaier/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houssemzaier/subscriptions","organizations_url":"https://api.github.com/users/houssemzaier/orgs","repos_url":"https://api.github.com/users/houssemzaier/repos","events_url":"https://api.github.com/users/houssemzaier/events{/privacy}","received_events_url":"https://api.github.com/users/houssemzaier/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/spring-guides/tut-spring-boot-oauth2/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-24T10:46:20Z","updated_at":"2016-02-24T11:27:02Z","closed_at":null,"body":"Hi Spring Developer and Spring Lovers,\r\nFirst of all I want to thank you for this great free tutorial to start learning about the newest modern tools that Spring Framework give us for free. \r\nNext I have read this paragraph:\r\n\r\n--------------------------------------------------\r\n## How to Add a Local User Database:\r\n\r\nMany applications need to hold data about their users locally, even if authentication is delegated to an external provider. We don’t show the code here, but it is easy to do in two steps.\r\n\r\nChoose a backend for your database, and set up some repositories (e.g. using Spring Data) for a custom User object that suits your needs and can be populated, fully or partially, from the external authentication.\r\n\r\nProvision a User object for each unique user that logs in by inspecting the repository in your /user endpoint. If there is already a user with the identity of the current Principal, it can be updated, otherwise created.\r\n\r\nHint: add a field in the User object to link to a unique identifier in the external provider (not the user’s name, but something that is unique to the account in the external provider)\r\n\r\n--------------------------------------------------\r\n\r\nThis was a quite simple and I have understand it but because I am new to the spring framework I can not get more than the user's name from the principal paramater passed into this method:\r\n  @RequestMapping({ \"/user\", \"/me\" })\r\n    public Principal user(Principal principal){\r\nWhile I can get all the desired info in the frontEnd as a JSON format.\r\n\r\n_**So finally my question is how can I get some details about the User Authentication like url to his account with the spring/java apis**_.\r\n\r\nI had an idea in my mind and I know that it is not the best solution to do the job but it works: \r\nit is based on creating a Bean for UserInfo witch has all the info required to parse from the path \"/user\" then I use the RestTemplate to call this resource and then it parse the needed data. \r\nIt is that it is not the best way to do that so please;\r\nTHANKS IN ADVANCE\r\n"},"comment":{"url":"https://api.github.com/repos/spring-guides/tut-spring-boot-oauth2/issues/comments/188206487","html_url":"https://github.com/spring-guides/tut-spring-boot-oauth2/issues/8#issuecomment-188206487","issue_url":"https://api.github.com/repos/spring-guides/tut-spring-boot-oauth2/issues/8","id":188206487,"user":{"login":"dsyer","id":124075,"avatar_url":"https://avatars.githubusercontent.com/u/124075?v=3","gravatar_id":"","url":"https://api.github.com/users/dsyer","html_url":"https://github.com/dsyer","followers_url":"https://api.github.com/users/dsyer/followers","following_url":"https://api.github.com/users/dsyer/following{/other_user}","gists_url":"https://api.github.com/users/dsyer/gists{/gist_id}","starred_url":"https://api.github.com/users/dsyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dsyer/subscriptions","organizations_url":"https://api.github.com/users/dsyer/orgs","repos_url":"https://api.github.com/users/dsyer/repos","events_url":"https://api.github.com/users/dsyer/events{/privacy}","received_events_url":"https://api.github.com/users/dsyer/received_events","type":"User","site_admin":false},"created_at":"2016-02-24T11:27:02Z","updated_at":"2016-02-24T11:27:02Z","body":"Downcast the `Principal` to an `Authentication` (or possibly `OAuth2Authentication` and grab the `userAuthentication` from that) and then look in the `details` property. If your user was authenticated using a `UserInfoTokenServices` you will see the `Map` returned from the external provider's user info endpoint."}}