/// <summary>
 /// Authentication Code : codeからAccess Tokenを取得する。
 /// </summary>
 /// <param name="tokenEndpointUri">TokenエンドポイントのUri</param>
 /// <param name="client_id">client_id</param>
 /// <param name="client_secret">client_secret</param>
 /// <param name="redirect_uri">redirect_uri</param>
 /// <param name="code">code</param>
 /// <param name="authMethod">OAuth2AndOIDCEnum.AuthMethods</param>
 /// <returns>結果のJSON文字列</returns>
 public static async Task <string> GetAccessTokenByCodeAsync(
     Uri tokenEndpointUri, string client_id, string client_secret, string redirect_uri, string code,
     OAuth2AndOIDCEnum.AuthMethods authMethod = OAuth2AndOIDCEnum.AuthMethods.client_secret_basic)
 {
     return(await OAuth2AndOIDCClient.GetAccessTokenByCodeAsync(
                tokenEndpointUri, client_id, client_secret, redirect_uri, code, null, null, authMethod));
 }
 /// <summary>
 /// FAPI1 : code, assertionからAccess Tokenを取得する。
 /// </summary>
 /// <param name="tokenEndpointUri">TokenエンドポイントのUri</param>
 /// <param name="redirect_uri">redirect_uri</param>
 /// <param name="code">code</param>
 /// <param name="assertion">assertion</param>
 /// <param name="authMethod">OAuth2AndOIDCEnum.AuthMethods</param>
 /// <returns>結果のJSON文字列</returns>
 public static async Task <string> GetAccessTokenByCodeAsync(
     Uri tokenEndpointUri, string redirect_uri, string code, string assertion,
     OAuth2AndOIDCEnum.AuthMethods authMethod = OAuth2AndOIDCEnum.AuthMethods.private_key_jwt)
 {
     return(await OAuth2AndOIDCClient.GetAccessTokenByCodeAsync(
                tokenEndpointUri, null, null, redirect_uri, code, null, assertion, authMethod));
 }
Beispiel #3
0
        /// <summary>constructor</summary>
        public JwkSetStore()
        {
            if (string.IsNullOrEmpty(OAuth2AndOIDCParams.JwkSetUri))
            {
                this._jwkSet = new JwkSet();
            }
            else
            {
                // _jwkSet 更新
                this._jwkSet = JsonConvert.DeserializeObject <JwkSet>(
                    OAuth2AndOIDCClient.GetJwkSetAsync(
                        new Uri(OAuth2AndOIDCParams.JwkSetUri)).Result);

                // _dateTime 更新
                this._dateTime = DateTime.Now;

                if (this._jwkSet.keys.Count == 0)
                {
                    Debug.WriteLine("JwkSet was abnormally initarized with an empty state in JwkSetStore constructor.");
                }
                else
                {
                    Debug.WriteLine("JwkSet was initarized normally in JwkSetStore constructor.");
                }
            }
        }
 /// <summary>
 ///PKCE : code, code_verifierからAccess Tokenを取得する。
 /// </summary>
 /// <param name="tokenEndpointUri">TokenエンドポイントのUri</param>
 /// <param name="client_id">client_id</param>
 /// <param name="client_secret">client_secret</param>
 /// <param name="redirect_uri">redirect_uri</param>
 /// <param name="code">code</param>
 /// <param name="code_verifier">code_verifier</param>
 /// <returns>結果のJSON文字列</returns>
 public static async Task <string> GetAccessTokenByCodeAsync(
     Uri tokenEndpointUri, string client_id, string client_secret, string redirect_uri, string code, string code_verifier)
 {
     return(await OAuth2AndOIDCClient.GetAccessTokenByCodeAsync(
                tokenEndpointUri, client_id, client_secret, redirect_uri, code, code_verifier, null));
 }
 /// <summary>
 /// FAPI1 : code, assertionからAccess Tokenを取得する。
 /// </summary>
 /// <param name="tokenEndpointUri">TokenエンドポイントのUri</param>
 /// <param name="redirect_uri">redirect_uri</param>
 /// <param name="code">code</param>
 /// <param name="assertion">assertion</param>
 /// <returns>結果のJSON文字列</returns>
 public static async Task <string> GetAccessTokenByCodeAsync(
     Uri tokenEndpointUri, string redirect_uri, string code, string assertion)
 {
     return(await OAuth2AndOIDCClient.GetAccessTokenByCodeAsync(
                tokenEndpointUri, null, null, redirect_uri, code, null, assertion));
 }
Beispiel #6
0
        /// <summary>SetJwkSetObjectAsync</summary>
        /// <param name="jku">string</param>
        /// <param name="kid">string</param>
        /// <returns>JwkObject</returns>
        public JObject SetJwkSetObject(string jku, string kid)
        {
            if (jku != OAuth2AndOIDCParams.JwkSetUri)
            {
                // 一致しなかった場合、以下の処理を施しリトライ。
                if (jku.EndsWith("/"))
                {
                    jku = jku.Substring(0, jku.Length - 1);
                }
                else
                {
                    jku = jku + "/";
                }

                if (jku != OAuth2AndOIDCParams.JwkSetUri)
                {
                    return(null); // 上位で証明書利用へ遷移
                }
            }

            try
            {
                // ライターロックを取得
                this._rwLock.AcquireWriterLock(Timeout.Infinite);

                #region 書込

                TimeSpan timeSpan = DateTime.Now.Subtract(this._dateTime);

                if (timeSpan.TotalSeconds < OAuth2AndOIDCParams.JwkSetUpdateIntervalInSeconds)
                {
                    // x秒(既定10秒)以内に更新済み ≒ 更新済みと判断。
                }
                else
                {
                    // x秒(既定10秒)以内に更新済みでない
                    // ≒ 鍵変更後、更新済みでないと判断。

                    // JwkSetUri
                    string jwkSetString = OAuth2AndOIDCClient.GetJwkSetAsync(new Uri(jku)).Result;

                    if (string.IsNullOrEmpty(jwkSetString))
                    {
                        // jwkSetStringが空文字列
                        Debug.WriteLine("JwkSet was not updated, because jwkSetString is null or empty in JwkSetStore.SetJwkSetObject method.");
                    }
                    else
                    {
                        JwkSet jwkSet = JsonConvert.DeserializeObject <JwkSet>(jwkSetString);

                        // _jwkSet 更新
                        this._jwkSet = jwkSet;
                        // _dateTime 更新
                        this._dateTime = DateTime.Now;

                        Debug.WriteLine("JwkSet was updated normally in JwkSetStore.SetJwkSetObject method.");
                    }
                }

                #endregion
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception was catched in JwkSetStore.SetJwkSetObject method: " + ex.ToString());
            }
            finally
            {
                // ライターロックを解放
                this._rwLock.ReleaseWriterLock();
            }

            // JwkSetからJwkを返す。
            return(JwkSet.GetJwkObject(this._jwkSet, kid));
        }