static void Main(string[] args) { Dictionary <string, Dictionary <string, string> > obj = new Dictionary <string, Dictionary <string, string> >(); for (int i = 0; i < 5; i++) { obj.Add( Guid.NewGuid().ToString("N"), new Dictionary <string, string>() { { "client_secret", GetPassword.Base64UrlSecret(32) }, { "redirect_uri_code", "http://hogehoge" + i.ToString() + "/aaa" }, { "redirect_uri_token", "http://hogehoge" + i.ToString() + "/bbb" }, { "client_name", "hogehoge" + i.ToString() } }); } string json = JsonConvert.SerializeObject(obj, Formatting.Indented); Console.WriteLine(json); //obj = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<string, string>>>(json); //json = Console.ReadLine(); }
public ActionResult AuthorizationCode_PKCE_S256() { this.Init(); this.CodeVerifier = GetPassword.Base64UrlSecret(50); this.CodeChallenge = OAuth2AndOIDCClient.PKCE_S256_CodeChallengeMethod(this.CodeVerifier); this.Save(); // Authorization Code Flow (PKCE S256) return(Redirect(this.AssembleOAuth2Starter( OAuth2AndOIDCConst.AuthorizationCodeResponseType) + "&code_challenge=" + this.CodeChallenge + "&code_challenge_method=" + OAuth2AndOIDCConst.PKCE_S256)); }
public ActionResult AuthorizationCode_PKCE_Plain() { this.Init(); this.CodeVerifier = GetPassword.Base64UrlSecret(50); this.CodeChallenge = this.CodeVerifier; this.Save(); // Authorization Code Flow (PKCE plain) return(Redirect(this.AssembleOAuth2Starter( ASPNETIdentityConst.AuthorizationCodeResponseType) + "&code_challenge=" + this.CodeChallenge + "&code_challenge_method=plain")); }
/// <summary>CreateRefreshToken</summary> /// <param name="context"></param> private void CreateRefreshToken(AuthenticationTokenCreateContext context) { // context.SetToken(context.SerializeTicket()); // -------------------------------------------------- if (ASPNETIdentityConfig.EnableRefreshToken) { // EnableRefreshToken == true string token = GetPassword.Base64UrlSecret(128); // Guid.NewGuid().ToString(); // copy properties and set the desired lifetime of refresh token. AuthenticationProperties refreshTokenProperties = new AuthenticationProperties(context.Ticket.Properties.Dictionary) { // IssuedUtcとExpiredUtcという有効期限プロパティをAuthenticationTicketに追加 IssuedUtc = context.Ticket.Properties.IssuedUtc, ExpiresUtc = DateTime.UtcNow.Add(ASPNETIdentityConfig.OAuthRefreshTokenExpireTimeSpanFromDays) // System.TimeSpan.FromSeconds(20)) // Debug時 }; // AuthenticationTicket.IdentityのClaimsIdentity値を含む有効期限付きの新しいAuthenticationTicketを作成する。 AuthenticationTicket refreshTokenTicket = new AuthenticationTicket(context.Ticket.Identity, refreshTokenProperties); // 新しいrefreshTokenTicketをConcurrentDictionaryに保存 // consider storing only the hash of the handle. TicketSerializer serializer = new TicketSerializer(); byte[] bytes = serializer.Serialize(refreshTokenTicket); switch (ASPNETIdentityConfig.UserStoreType) { case EnumUserStoreType.Memory: RefreshTokenProvider.RefreshTokens.TryAdd(token, refreshTokenTicket); break; case EnumUserStoreType.SqlServer: case EnumUserStoreType.ODPManagedDriver: case EnumUserStoreType.PostgreSQL: // DMBMS using (IDbConnection cnn = DataAccess.CreateConnection()) { cnn.Open(); switch (ASPNETIdentityConfig.UserStoreType) { case EnumUserStoreType.SqlServer: cnn.Execute( "INSERT INTO [RefreshTokenDictionary] ([Key], [Value], [CreatedDate]) VALUES (@Key, @Value, @CreatedDate)", new { Key = token, Value = bytes, CreatedDate = DateTime.Now }); break; case EnumUserStoreType.ODPManagedDriver: cnn.Execute( "INSERT INTO \"RefreshTokenDictionary\" (\"Key\", \"Value\", \"CreatedDate\") VALUES (:Key, :Value, :CreatedDate)", new { Key = token, Value = bytes, CreatedDate = DateTime.Now }); break; case EnumUserStoreType.PostgreSQL: cnn.Execute( "INSERT INTO \"refreshtokendictionary\" (\"key\", \"value\", \"createddate\") VALUES (@Key, @Value, @CreatedDate)", new { Key = token, Value = bytes, CreatedDate = DateTime.Now }); break; } } break; } context.SetToken(token); } else { // EnableRefreshToken == false } }