Пример #1
0
        public ActionResult Authenticate(string success, string failure, string permissions, string state, bool offline)
        {
            string key = Guid.NewGuid().ToStringValue();

            OAuthState authState = new OAuthState();

            authState.FailureUrl = failure;
            authState.SuccessUrl = success;
            authState.State      = state;

            this.stateManager.SaveState(key, authState);

            IDictionary <string, string> parameters = new Dictionary <string, string>();

            if (offline)
            {
                parameters.Add("access_type", "offline");
            }

            List <string> permissionList = new List <string>();

            if (!string.IsNullOrWhiteSpace(permissions))
            {
                permissionList.AddRange(permissions.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries));
            }

            GoogleClient client = new GoogleClient(this.context.Config.Social.Google.AppID,
                                                   this.context.Config.Social.Google.AppSecret);

            string authorizationUrl = client.BuildAuthorizationUrl(SocialApiSetting.BuildUrl(this.context.Config.Social.Google.Domain, "social/google/authorize"), permissionList, key, parameters);

            return(new RedirectResult(authorizationUrl));
        }