public OdnoklassnikiTokenDataExtractor(IPortalFrontendSettings settings)
        {
            // Pass your credentials to the service
            string applicationId = settings.OkApplicationId;
            string appSecret = settings.OkApplicationSecret;
            string appPublic = settings.OkApplicationPublic;

            _service = new OkClient(applicationId, appSecret, appPublic);
        }
예제 #2
0
        public Uri GetAutheticationUri(IDictionary<string, string> parameters, Uri callback)
        {
            var callbackUri = new UriBuilder(callback)
            {
                Query = string.Format("context={0}", parameters["wctx"])
            };

            // Pass your credentials to the service
            string appId = _settings.OkApplicationId;
            string appSecret = _settings.OkApplicationSecret;
            string appPublic = _settings.OkApplicationPublic;

            var service = new OkClient(appId, appSecret, appPublic);

            // Redirect to the OAuth Authorization URL
            return service.GetAuthorizationUri(string.Empty, callbackUri.ToString());
        }
예제 #3
0
        public string GetResponseHtml(IDictionary<string, string> parameters, Uri signinUri)
        {
            string code = parameters["code"];

            // Exchange the Request Token for an Access Token
            string appId = _settings.OkApplicationId;
            string appSecret = _settings.OkApplicationSecret;
            string appPublic = _settings.OkApplicationPublic;

            string scheme = parameters["SERVER_PORT_SECURE"] == "1" ? "https" : "http";

            var callbackUri = new UriBuilder(string.Format("{0}://{1}", scheme, parameters["HTTP_HOST"]))
            {
                Path = parameters["URL"],
                Query = string.Format("context={0}", parameters["context"])
            };

            var service = new OkClient(appId, appSecret, appPublic);
            dynamic accessToken = service.GetAccessToken(code, callbackUri.ToString());

            dynamic token = accessToken.access_token;
            service.AuthenticateWith(token.ToString());

            // Claims
            dynamic user = service.Get("users.getCurrentUser");

            string acsNamespace = _settings.AcsNamespace;
            string wtRealm = string.Format(WtRealm, acsNamespace);
            string wReply = string.Format(WReply, acsNamespace);

            var requestMessage = new SignInRequestMessage(signinUri, wtRealm, wReply);

            // Add extracted claims
            var identity = new ClaimsIdentity(AuthenticationTypes.Federation);
            identity.AddClaim(new Claim(ClaimTypes.Name, user.name.ToString()));
            identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.uid.ToString()));
            identity.AddClaim(new Claim(OkClaims.OkToken, token.ToString()));

            var principal = new ClaimsPrincipal(identity);

            SignInResponseMessage responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, principal, this);
            responseMessage.Context = parameters["context"];

            return responseMessage.WriteFormPost();
        }