예제 #1
0
        public OAuthV2ResponseObject ManageUserAuthCallback()
        {
            if (HttpContext.Current == null)
            {
                throw new Exception("No web context");
            }
            if (HttpContext.Current.Request["code"] == null)
            {
                throw new Exception("No access code returned");
            }

            // Read access code provided by Omron.
            OAuthV2SessionManager.AccessCode = HttpContext.Current.Request["code"];

            // Use this code to request Access token.
            Uri           uriGetAccesToken = new Uri(ENDPOINT_GET_ACCESS_TOKEN);
            StringBuilder sb = new StringBuilder();

            sb.Append("scope=" + String.Join(" ", SCOPE_offline_access, SCOPE_openid, SCOPE_bloodpressure, SCOPE_activity));
            sb.Append("&grant_type=" + GRANT_TYPE_AUTHORIZATION_CODE);
            sb.Append("&client_id=" + _ClientId);
            sb.Append("&client_secret=" + _ClientSecret);
            sb.Append("&code=" + OAuthV2SessionManager.AccessCode);
            sb.Append("&redirect_uri=" + _RedirectUrl.ToString());

            var response = OAuthV2RequestHelper.SendRequest(uriGetAccesToken, sb.ToString());

            // Populate Session variables
            OAuthV2SessionManager.AccessToken  = response.AccessToken;
            OAuthV2SessionManager.RefreshToken = response.RefreshToken;
            OAuthV2SessionManager.UserId       = response.UserId;

            return(response);
        }
예제 #2
0
        public OAuthV2ResponseObject RefreshAccessToken()
        {
            if (!OAuthV2SessionManager.IsAccessTokenSet())
            {
                throw new Exception("No access token set.");
            }
            if (!OAuthV2SessionManager.IsRefreshTokenSet())
            {
                throw new Exception("No refresh token set.");
            }

            // Refresh Access Token
            Uri           uriGetAccesToken = new Uri(ENDPOINT_REFRESH_ACCESS_TOKEN);
            StringBuilder sb = new StringBuilder();

            sb.Append("grant_type=" + GRANT_TYPE_REFRESH_TOKEN);
            sb.Append("&client_id=" + _ClientId);
            sb.Append("&client_secret=" + _ClientSecret);
            sb.Append("&redirect_uri=" + _RedirectUrl);
            sb.Append("&refresh_token=" + OAuthV2SessionManager.RefreshToken);

            var response = OAuthV2RequestHelper.SendRequest(uriGetAccesToken, sb.ToString());

            // Populate Session variables
            OAuthV2SessionManager.AccessToken  = response.AccessToken;
            OAuthV2SessionManager.RefreshToken = response.RefreshToken;

            return(response);
        }