Do we always have to sign in?

Apr 30, 2007 at 7:08 PM
I'm working on a website for my church and there will be many, many people viewing the gallery... and I don't want any of them knowing the flickr information, or going to that page.

how can I make it so they never have to see that page, regardless of who looks at my images page?
Coordinator
May 1, 2007 at 8:39 AM

rternier wrote:
I'm working on a website for my church and there will be many, many people viewing the gallery... and I don't want any of them knowing the flickr information, or going to that page.

how can I make it so they never have to see that page, regardless of who looks at my images page?


Well the simple answer is - don't send them there...

If they are being sent to the Flickr authentication page then you must be writing a Response.Redirect line somewhere, correct?

If it is the case that the photos you are trying to show are private and you need to be authenticated, then you are wanting to store the authentication token from when YOU authenticate and use that.

Otherwise I'm not sure what your question relates to.
May 5, 2007 at 9:48 PM
Edited May 6, 2007 at 3:29 AM
The pictures I am looking at are private.

Whenever I try to authenticate it asks me to sign in, which is what I'm trying to get away from.

-------Edit

here's the code I have - any idea?

protected void Initialize()
{
if(Request.QueryString"frob" != null)
{
Cache"flickrFrob" = Request.QueryString"frob";
}

if (Cache"flickrFrob" == null)
{
flickr = new FlickrNet.Flickr();
string auth_url = flickr.AuthCalcWebUrl(FlickrNet.AuthLevel.Read);
Response.Redirect(auth_url);
}

if (Cache"flickrToken" == null)
{
flickr = new FlickrNet.Flickr();
FlickrNet.Auth auth = flickr.AuthGetToken(Cache"flickrFrob".ToString());
Cache"flickrToken" = auth.Token;
}
this.LoadImageListDropDown(ddlImageList);

}

private void LoadImageListDropDown(DropDownList dropdownList)
{
try
{
if(flickr == null)flickr = new FlickrNet.Flickr();

FlickrNet.Photosets photoSets = flickr.PhotosetsGetList(ConfigurationManager.AppSettings.Get("UserID"));
dropdownList.DataSource = photoSets.PhotosetCollection;
dropdownList.DataTextField = "Description";
dropdownList.DataValueField = "PhotosetId";
dropdownList.DataBind();
}
catch (FlickrNet.FlickrException fex)
{
Response.Write(fex.ToString());
}
}
--- Solved it.

I thought when you did: FlickrNet.Auth auth = flickr.AuthGetToken(Cache"flickrFrob".ToString());
that it actually SET the token in the flickr object - that is not the case. I had to do this afterwards:

flickr.ApiToken = auth.Token;

and then it worked.
May 7, 2007 at 4:28 AM
Hrm, I think it worked because that session was signed into Yahoo Flickr already.

here is my code that is called when the page loads. And I would like all the pictures to be private, and not have to sign in (is that posible?)
----

if(Request.QueryString"frob" != null)
{
Cache"flickrFrob" = Request.QueryString"frob";
}

if (Cache"flickrFrob" == null)
{
flickr = new FlickrNet.Flickr();
string auth_url = flickr.AuthCalcWebUrl(FlickrNet.AuthLevel.Read);
Response.Redirect(auth_url);
}

this.CheckFlickrToken();

this.LoadImageListDropDown(ddlImageList);
this.LoadImageListDropDown(ddlUploadImageSetList);


...

private void CheckFlickrToken()
{
if(flickr == null)flickr = new FlickrNet.Flickr();

if (Cache"flickrToken" == null)
{
FlickrNet.Auth auth = flickr.AuthGetToken(Cache"flickrFrob".ToString());
Cache"flickrToken" = auth.Token;
flickr.ApiToken = auth.Token;
}
else
{
flickr.ApiToken = Cache"flickrToken".ToString();
}
}
Coordinator
May 8, 2007 at 10:50 AM
if you change the line

if (Cache["flickrFrob"] == null)
{
    flickr = new FlickrNet.Flickr();
    string auth_url = flickr.AuthCalcWebUrl(FlickrNet.AuthLevel.Read);
    Response.Redirect(auth_url);
}

to

if (Cache["flickrFrob"] == null && Cache["flickrToken"] == null)
{
    flickr = new FlickrNet.Flickr();
    string auth_url = flickr.AuthCalcWebUrl(FlickrNet.AuthLevel.Read);
    Response.Redirect(auth_url);
}

i.e. You should only do the Response.Redirect if there is no cached token.
Coordinator
May 8, 2007 at 11:05 AM
If you want to display YOUR private photos to other users of your web site, then you just need to hard code the authentication token in your code, either in an web.config or hard coded.
May 9, 2007 at 5:34 AM
Is the Authentication Token always the same? Ie. will it never change?

Coordinator
May 9, 2007 at 9:29 AM

rternier wrote:
Is the Authentication Token always the same? Ie. will it never change?


It doesn't expire unless a) You unauthenticate the application via Flickr, or b) You request a new frob. So you can store it and keep using it as long as you want.
Jul 2, 2009 at 8:54 PM

Hi Guys,

I'm trying to copy this model but it never actually takes me to a page in flickr that I have to verify. Any idea why?

 

Here is my code which gets called on Page_Load

 

        FlickrWrapper _wrapper; //This is my class

        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["FlickrWrapper"] != null)
            {
                _wrapper = HttpContext.Current.Session["FlickrWrapper"] as Sparebackup.ThirdParty.Flickr.FlickrWrapper;
            }
            else
            {
                _wrapper = new Sparebackup.ThirdParty.Flickr.FlickrWrapper();
                HttpContext.Current.Session.Add("FlickrWrapper", _wrapper);
            }

            _wrapper.Authenticate("");

        }

 

        public bool Authenticate(string callback_url)
        {
            if (_flickr == null) _flickr = new FlickrNet.Flickr(_key, _secret);

            //Check to see if you have frob and set it to flickrFrob
            //Get the flicker token too
            if (HttpContext.Current.Request.QueryString["frob"] != null)
            {
                HttpContext.Current.Session["flickrFrob"] = HttpContext.Current.Request.QueryString["frob"];

                if (HttpContext.Current.Session["flickrAuth"] != null)
                {
                    _auth = HttpContext.Current.Session["flickrAuth"] as Auth;
                    _flickr.AuthToken = _auth.Token.ToString();
                }
                else
                {
                    _auth = _flickr.AuthGetToken(HttpContext.Current.Session["flickrFrob"].ToString());
                    HttpContext.Current.Session["flickrAuth"] = _auth;
                    _flickr.AuthToken = _auth.Token;
                }
            }

            //If you don't have flickrFrob, then redirect to get the frob.
            if (HttpContext.Current.Session["flickrFrob"] == null)
            {
                string auth_url = _flickr.AuthCalcWebUrl(FlickrNet.AuthLevel.Write);
                HttpContext.Current.Response.Redirect(auth_url);
                return false;
            }


           
            return true;

        }

Coordinator
Jul 2, 2009 at 10:16 PM

I'm not sure why your code it's working. I would say that there is no point at all in storing the frob in the session, as once you have used it once you cannot use it again.

I would write it something like this - this is basically the reverse order of the way you have it - you check the most likely thing first (that you are already logged in) and then go down the line, finally redirecting if the user is not logged in (this is pseudo code and will not compile):

HttpContext current = HttpContext.Current;

if( current.Session["flickrAuth"] != null )
{
  _auth = current.Session["flickrAuth"];
  _flickr.AuthToken = _auth;
  return true;
}

if( current.Request.QueryString["frob"] != null )
{
   _auth = _flickr.AuthGetToken(current.Request.QueryString["frob"]);
   _flickr.AuthToken = _auth.Token;
  return true;
}

string authUrl = _flickr.AuthCalcWebUrl(FlickrNet.AuthLevel.Write);
current.Response.Redirect(authUrl);
return false;