Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7647369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:26:42+00:00 2026-05-31T10:26:42+00:00

I want to use DotNetOpenAuth in my website for authentication + authorization (gmail). However,

  • 0

I want to use DotNetOpenAuth in my website for authentication + authorization (gmail).

However, I would like to ask: What should I persist?

I thought:

  1. In the DB: for each user save a Guid and his gmail (fetched)
  2. In formAuthentication cookie the Guid I have assigned to that user.

Any other suggestions?

public bool Login()
{
    IAuthenticationResponse authResponse = GoogleConsumerHandler.RelyingParty.GetResponse();
    if (authResponse != null)
    {
        HandleAuthResponse(authResponse);
    }
    else
    {
        HandleAuthNullResponse(authResponse);
    }

    return false;
}

#region private methods

private void HandleAuthResponse(IAuthenticationResponse authResponse)
{
    switch (authResponse.Status)
    {
        case AuthenticationStatus.Authenticated:
            State.FetchResponse = authResponse.GetExtension<FetchResponse>();
            var consumer = new WebConsumer(GoogleConsumerHandler.ServiceDescription, mConsumerTokenManager);
            AuthorizedTokenResponse accessToken = consumer.ProcessUserAuthorization(authResponse);
            if (accessToken != null)
            {                  
                var email = authResponse.ClaimedIdentifier;

                //existing or new
                Guid userId = mCRMService.GetUserId(email, accessToken.AccessToken);

                State.GoogleAccessToken = accessToken.AccessToken;

                FormsAuthentication.SetAuthCookie(userId.ToString(), false);

                //authenticat and authorized
                //Response.Redirect("~/Browser.htm");
            }
            else
            {
                //authenticated and not authorized
                //MultiView1.SetActiveView(AuthorizationDenied);
            }
            break;

        case AuthenticationStatus.Canceled:
            break;
        case AuthenticationStatus.Failed:
            break;
        default:
            //not authenticated
            //this.MultiView1.SetActiveView(this.AuthenticationFailed);
            break;
    }
}

private void HandleAuthNullResponse(IAuthenticationResponse authResponse)
{
    // Google requires that the realm and consumer key be equal,
    // so we constrain the realm to match the realm in the web.config file.
    // This does mean that the return_to URL must also fall under the key,
    // which means this sample will only work on a public web site
    // that is properly registered with Google.
    // We will customize the realm to use http or https based on what the
    // return_to URL will be (which will be this page).

    var consumer = new WebConsumer(GoogleConsumerHandler.ServiceDescription, mConsumerTokenManager);

    //Realm realm = "http://localhost:8976/";
    Realm realm = System.Web.HttpContext.Current.Request.Url.Scheme + Uri.SchemeDelimiter + consumer.ConsumerKey + "/";
    IAuthenticationRequest authReq = GoogleConsumerHandler.RelyingParty.CreateRequest(GoogleConsumerHandler.GoogleOPIdentifier, realm);

    // Prepare the OAuth extension
    string scope = GoogleConsumerHandler.GetScopeUri(GoogleConsumerHandler.Applications.Gmail);
    consumer.AttachAuthorizationRequest(authReq, scope);

    // We also want the user's email address
    var fetch = new FetchRequest();
    fetch.Attributes.AddRequired(WellKnownAttributes.Contact.Email);
    authReq.AddExtension(fetch);

    authReq.RedirectToProvider();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:26:43+00:00Added an answer on May 31, 2026 at 10:26 am

    For authentication purposes you should store the OpenID ClaimedIdentifier you get back in the IAuthenticationResponse object. That serves as the “primary key” for your users so you can recognize them when they return. I suggest you use the claimed_id as the FormsAuthentication username instead of a random GUID as well. Also storing the email address you collect is fine, but it’s inadvisable to use that as the means to recognize a returning user.

    Remember that you can’t log in “gmail users”. You can log in OpenID users, that may use any Provider. You can limit that to “Google” users by filtering on the IAuthenticationResponse.Provider.Uri for the Google OP Endpoint, but even then you’re not guaranteed that those accounts use Gmail (their email address might be foo@bar.com anyway).

    Finally, if all you need is their authentication and email address (whatever email that is) you can do so using the OpenID AX extension (built into DNOA) and you don’t need “authorization”, which might greatly simplify your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use DotNetOpenAuth to create something like this Is is authentication or
I use dotnetOpenAuth. I want to request authorization to the user's gamil. Do I
i want use some data from a website with web service. i have a
I want to use the Publish.GacRemove function to remove an assembly from GAC. However,
I'm building an ASP.NET MVC site where I want to use DotNetOpenAuth to implement
If I want to integrate DotNetOpenAuth (primary for people to use their Google/Yahoo accounts
Where are the Gnulib files in Linux? I want use lib like safe-read, mbchar,
I want use a query like such SELECT personId FROM Person p Inner Join
I want to ccreate a website that reads one's Gmails headers. If I use
I use DotNetOpenAuth in my Asp.Net application. I want to create a login page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.