public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("urn:google:name", context.Identity.FindFirstValue(ClaimTypes.Name))); context.Identity.AddClaim(new Claim("urn:google:email", context.Identity.FindFirstValue(ClaimTypes.Email))); context.Identity.AddClaim(new Claim("access_token", context.AccessToken, ClaimValueTypes.String, "Google")); return(Task.FromResult <object>(null)); }
public async Task Authenticated(GoogleOAuth2AuthenticatedContext context) { var userId = await _users.CreateOrReplaceUserAsync(context.Identity.AuthenticationType, context.Id, context.Name, context.Email); context.Identity.AddClaim(new System.Security.Claims.Claim(Security.ClaimTypes.AccessToken, context.AccessToken)); context.Identity.AddClaim(new System.Security.Claims.Claim(Security.ClaimTypes.UserId, userId)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); context.Identity.AddClaim(new Claim("Image", context.User.GetValue("image").ToString())); context.Identity.AddClaim(new Claim("Email", context.Email)); return(Task.FromResult <object>(null)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); //context.Identity.AddClaim(new Claim(AuthorizationCore.CLAIM_IDENTITY_TYPE, context.Email)); context.Identity.AddClaim(new Claim("Email", context.Email)); return(Task.FromResult <object>(null)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); //context.Identity.AddClaim(new Claim(ClaimTypes.DateOfBirth, context.User["birthday"].ToString())); //context.Identity.AddClaim(new Claim(ClaimTypes.GivenName, context.User["name"]["givenname"].ToString())); //context.Identity.AddClaim(new Claim(ClaimTypes.Surname, context.User["name"]["familyname"].ToString())); //context.Identity.AddClaim(new Claim(ClaimTypes.Gender, context.User["gender"].ToString())); return(Task.FromResult <object>(null)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); context.Identity.AddClaim(new Claim("Name", context.Name)); context.Identity.AddClaim(new Claim("Email", context.Email)); context.Identity.AddClaim(new Claim("Profile", context.User.GetValue("url") != null ? context.User.GetValue("url").ToString() : String.Empty)); context.Identity.AddClaim(new Claim("Picture", context.User.GetValue("image").Value <string>("url"))); return(Task.FromResult(0)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); context.Identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.Id)); //context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.Email)); //context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email)); //context.Identity.AddClaim(new Claim(ClaimTypes.Surname, context.GivenName)); //context.Identity.AddClaim(new Claim(ClaimTypes.GivenName, context.FamilyName)); return(Task.FromResult <object>(null)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); var pictureUrl = context.User["image"].Value <string>("url"); // Pass the picture url as a claim to be used later in the application context.Identity.AddClaim(new Claim("PictureUrl", pictureUrl)); return(Task.FromResult <object>(null)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); if (context.Email != null) { context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email)); } return(Task.FromResult <object>(null)); }
public override Task Authenticated(GoogleOAuth2AuthenticatedContext context) { var result = base.Authenticated(context); var owin = HttpContext.Current.GetOwinContext(); var auth = owin.Authentication; var identity = auth.User.Identity as ClaimsIdentity; // // store things I want in the database // return(result); }
public override Task Authenticated(GoogleOAuth2AuthenticatedContext context) { string avatarUrl = context.User .SelectToken("image.url") .ToString() .Replace("sz=50", "sz=240"); context.Identity.AddClaim( new Claim(OwinHelper.ClaimTypeAvatarUrl, avatarUrl)); return(base.Authenticated(context)); }
public static User NewUser(this GoogleOAuth2AuthenticatedContext context) { var user = new User() { Email = context.Email, First = context.GivenName, Last = context.FamilyName, IsOrganizationAdmin = false, OrganizationId = 1 }; return(user); }
// public override Task Authenticated(GoogleOAuth2AuthenticatedContext context) { try { addClaim(context.Identity, "urn:tokens:googleplus:accesstoken", context.AccessToken); // addClaim(context.Identity, "urn:tokens:googleplus:familyname", context.FamilyName); addClaim(context.Identity, "urn:tokens:googleplus:givenname", context.GivenName); addClaim(context.Identity, "urn:tokens:googleplus:avatarurl", getValuesInPath(context.User, "image.url").FirstOrDefault()); //?.Replace("sz=50", "sz=240") addClaim(context.Identity, "urn:tokens:googleplus:company", getValue(context.User, "company")); // //foreach (string oranisationName in getValuesInPath(context.User, "organizations.name")) { addClaim(context.Identity, "urn:tokens:googleplus:organization", oranisationName); } //addClaim(context.Identity, "urn:tokens:googleplus:gender", getValue(context.User, "gender")); //addClaim(context.Identity, "urn:tokens:googleplus:occupation", getValue(context.User, "occupation")); //addClaim(context.Identity, "urn:tokens:googleplus:aboutme", getValue(context.User, "aboutme")); //addClaim(context.Identity, "urn:tokens:googleplus:language", getValue(context.User, "language")); } catch (Exception ex) { Logger.Error(ex, LogCategory.Claims, "There was an issue reading the information from the Google Authentication context."); } // return(base.Authenticated(context)); }
Task IGoogleOAuth2AuthenticationProvider.Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); return(Task.FromResult <object>(null)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim(GenericNames.AUTHENTICATION_EXTERNAL_LOGIN, context.AccessToken)); return(Task.FromResult <object>(null)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); context.Identity.AddClaim(new Claim("UserId", context.Id)); return(Task.FromResult <object>(null)); }
public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { System.Security.Claims.Claim claim = new System.Security.Claims.Claim("ExternalAccessToken", context.AccessToken); context.Identity.AddClaim(claim); return(Task.FromResult <object>(null)); }
//G , F 驗證完畢 , 會透過 ASP.NET 預設的 http://localhost:1520/signin-google 進行導向。 //而導向完後,就會進入底下方法,並且於 context 紀錄登入過後的資訊 ( 也就是說,取得相關資訊的事情..MS都處理掉了.. ) public Task Authenticated(GoogleOAuth2AuthenticatedContext context) { //取得外部登入的存取 Token ,例如,取得存取 Google 帳號資訊的 Token context.Identity.AddClaim(new Claim("ExternalAccessToken", context.AccessToken)); return(Task.FromResult <object>(null)); }
protected override async Task <AuthenticationTicket> AuthenticateCoreAsync() { AuthenticationProperties properties = null; try { string code = null; string state = null; IReadableStringCollection query = Request.Query; IList <string> values = query.GetValues("code"); if (values != null && values.Count == 1) { code = values[0]; } values = query.GetValues("state"); if (values != null && values.Count == 1) { state = values[0]; } properties = Options.StateDataFormat.Unprotect(state); if (properties == null) { return(null); } // OAuth2 10.12 CSRF if (!ValidateCorrelationId(properties, _logger)) { return(new AuthenticationTicket(null, properties)); } string requestPrefix = Request.Scheme + "://" + Request.Host; string redirectUri = requestPrefix + Request.PathBase + Options.CallbackPath; // Build up the body for the token request var body = new List <KeyValuePair <string, string> >(); body.Add(new KeyValuePair <string, string>("grant_type", "authorization_code")); body.Add(new KeyValuePair <string, string>("code", code)); body.Add(new KeyValuePair <string, string>("redirect_uri", redirectUri)); body.Add(new KeyValuePair <string, string>("client_id", Options.ClientId)); body.Add(new KeyValuePair <string, string>("client_secret", Options.ClientSecret)); // Request the token HttpResponseMessage tokenResponse = await _httpClient.PostAsync(TokenEndpoint, new FormUrlEncodedContent(body)); tokenResponse.EnsureSuccessStatusCode(); string text = await tokenResponse.Content.ReadAsStringAsync(); // Deserializes the token response JObject response = JObject.Parse(text); string accessToken = response.Value <string>("access_token"); if (string.IsNullOrWhiteSpace(accessToken)) { _logger.WriteWarning("Access token was not found"); return(new AuthenticationTicket(null, properties)); } // Get the Google user HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, UserInfoEndpoint); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); HttpResponseMessage graphResponse = await _httpClient.SendAsync(request, Request.CallCancelled); graphResponse.EnsureSuccessStatusCode(); text = await graphResponse.Content.ReadAsStringAsync(); JObject user = JObject.Parse(text); var context = new GoogleOAuth2AuthenticatedContext(Context, user, response); context.Identity = new ClaimsIdentity( Options.AuthenticationType, ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); if (!string.IsNullOrEmpty(context.Id)) { context.Identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, context.Id, ClaimValueTypes.String, Options.AuthenticationType)); } if (!string.IsNullOrEmpty(context.GivenName)) { context.Identity.AddClaim(new Claim(ClaimTypes.GivenName, context.GivenName, ClaimValueTypes.String, Options.AuthenticationType)); } if (!string.IsNullOrEmpty(context.FamilyName)) { context.Identity.AddClaim(new Claim(ClaimTypes.Surname, context.FamilyName, ClaimValueTypes.String, Options.AuthenticationType)); } if (!string.IsNullOrEmpty(context.Name)) { context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.Name, ClaimValueTypes.String, Options.AuthenticationType)); } if (!string.IsNullOrEmpty(context.Email)) { context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Email, ClaimValueTypes.String, Options.AuthenticationType)); } if (!string.IsNullOrEmpty(context.Profile)) { context.Identity.AddClaim(new Claim("urn:google:profile", context.Profile, ClaimValueTypes.String, Options.AuthenticationType)); } context.Properties = properties; await Options.Provider.Authenticated(context); return(new AuthenticationTicket(context.Identity, context.Properties)); } catch (Exception ex) { _logger.WriteError("Authentication failed", ex); return(new AuthenticationTicket(null, properties)); } }