Ejemplo n.º 1
0
        public static string Auth(string callbackUrl, string state, Scope scope = Scope.None, Display display = Display.Page)
        {
            var parameters = new List<Parameter> {
                new Parameter { Name = OAuth2Parameter.ConsumerID.Value(), Value = clientId },
                new Parameter { Name = OAuth2Parameter.CallbackUrl.Value(), Value = callbackUrl },
                new Parameter { Name = OAuth2Parameter.State.Value(), Value = state }
            };

            if (display != Display.Page)
                parameters.Add(new Parameter { Name = OAuth2Parameter.Display.Value(), Value = display.Value() });

            if (scope != Scope.None) {
                var permissionNames = new List<string>();
                if ((scope & Scope.Email) == Scope.Email)
                    permissionNames.Add(Scope.Email.Value());
                if ((scope & Scope.Birthday) == Scope.Birthday)
                    permissionNames.Add(Scope.Birthday.Value());
                if ((scope & Scope.Publish) == Scope.Publish)
                    permissionNames.Add(Scope.Publish.Value());

                if (permissionNames.Count > 0)
                    parameters.Insert(0, new Parameter { Name = OAuth2Parameter.Scope.Value(), Value = string.Join(scopeDelimiter, permissionNames) });
            }

            return Utils.CreateUri(AuthorizeEndpoint, parameters).AbsoluteUri;
        }