Exemple #1
0
        public string GetSSOUrl(string returnUrl)
        {
            var url        = string.Format(ConfigurationUtilities.GetString("SSO.AuthorizationUrl"), ConfigurationUtilities.GetString("SSO.ClientId"));
            var encodedUrl = HttpUtility.UrlEncode(returnUrl);

            return($"{url}&redirect_uri={_postbackAuthUri}&state={encodedUrl}");
        }
Exemple #2
0
        public async System.Threading.Tasks.Task <string> Authorize(string code)
        {
            var client = new HttpClient();
            var secret = await GetClientSecret();

            // confirm legitimacy of the token
            var response = await client.RequestAuthorizationCodeTokenAsync(new AuthorizationCodeTokenRequest
            {
                Address = ConfigurationUtilities.GetString("SSO.TokenUrl"),

                ClientId     = ConfigurationUtilities.GetString("SSO.ClientId"),
                ClientSecret = secret,                ////ConfigurationUtilities.GetString("SSO.Secret"),

                Code        = code,
                RedirectUri = _postbackAuthUri
            });

            if (response.IsError)
            {
                throw new AuthenticationException(response.Error);
            }

            // get specific details about the user
            var userInfoResponse = await client.GetUserInfoAsync(new UserInfoRequest
            {
                Address = ConfigurationUtilities.GetString("SSO.UserInfoUrl"),

                Token = response.AccessToken
            });

            if (userInfoResponse.IsError)
            {
                throw new AuthenticationException(userInfoResponse.Error);
            }

            return(userInfoResponse.Json.TryGetString("uid"));

            //note: we can also parse other user details from json response if necessary. e.g.:
            //userInfoResponse.Json.TryGetString("givenName"),
            //userInfoResponse.Json.TryGetString("sn") };
        }
Exemple #3
0
 /// <summary>
 /// Upon Authorization, SSO should postback to this URL. By default, AI Apps should use /Account/Auth
 /// </summary>
 protected string GetAuthorizationPostbackUri()
 {
     ////return $"{requestContext.HttpContext.Request.Url.GetLeftPart(UriPartial.Authority)}/Account/Auth";
     return($"{ConfigurationUtilities.GetString("Shared.SiteBaseUrl") + ConfigurationUtilities.GetString("Shared.AuthorizationAction")}");
 }
Exemple #4
0
        private async System.Threading.Tasks.Task <string> GetClientSecret()
        {
            var secrets = new Secrets.Secret(new AmazonSecretsManagerClient());

            return(await secrets.GetSecret(ConfigurationUtilities.GetString("SSO.SecretKey")));
        }