Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Data From Authentication #25

Closed
NachoVazquez opened this issue Sep 27, 2016 · 7 comments
Closed

Getting Data From Authentication #25

NachoVazquez opened this issue Sep 27, 2016 · 7 comments
Labels

Comments

@NachoVazquez
Copy link

Please I'm struggling trying to get the data from the authenticated user could you made an tutorial explaining this. Thanks.

@kevinchalet
Copy link
Member

could you made an tutorial explaining this

Unfortunately, writing a tutorial needs time. Much more than I can dedicate to this project at this moment.

Have you tried the MVC sample?

@j2ghz
Copy link

j2ghz commented Oct 1, 2016

I have a similar problem. I created a new project .NET Core > ASP.NET Core Web Application (.NET Core) > Web Application (Change Authentication > Individual User Accounts), I added this nuget package and added a line to Startup.cs:

            app.UseIdentity();

            // Add external authentication middleware below. To configure them please see http://go.microsoft.com/fwlink/?LinkID=532715
            app.UseSteamAuthentication();

            app.UseMvc(
                routes => { routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });
        }

But I get just one claim from steam and that is

http://schemas.microsoft.com/ws/2008/06/identity/claims/authenticationmethod: Steam

@kevinchalet
Copy link
Member

@j2ghz you should at least get one claim: ClaimTypes.NameIdentifier (http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier)

To get more claims, create a new app via Steam's portal and register the application key you get in the Steam options:

app.UseSteamAuthentication(options => {
    options.ApplicationKey = "...";
});

@NachoVazquez
Copy link
Author

I did exactly what the MVC example shows, my problem is that when the OpenId server redirects to my page none controller catch the request and for that reason I can't get the values. Debugging I can see that I already have the values but I can access them from any controller.
Thanks Again and sorry for my English if I made any mistakes.

@NachoVazquez
Copy link
Author

This is what I get when the server redirects me, this with a white page. As you can see the address contains the data that I looking for, but I can't find a way to get it.
Also I have to say that i have to alter some constants in the implementation of the client because the server had some other values, for example openid.alias3 instead of openid.ax

http://localhost:10610/openid?state=CfDJ8AtrYQEuI5BNmfmQHh7HZDq2rbf8lzbXS_jQF3chWMa_usPliLwFiHrpOGjGkdFxYFUo5RSYUfq3eKOF1Lm1Pl7GOXbM5_pxeH0A79ULgoQmZ5xFoX8HYMWtZ-DiQfA4akr3qMcaXBE4vEr9gpjyoNFZCR5m3H_WBfqkGNUZKJUX63-g48NBdlUyVtz_jCJbrUWzKTbAntdF8ItBinWfHJL_Q8OFj8ygi1Gz9y7QXXmpPmWHZj2IGksfJnrPDt31Yg&openid.claimed_id=https%3A%2F%2Flogin.uh.cu%2Fuser%2Fjose.vazquez%40iris.uh.cu&openid.identity=https%3A%2F%2Flogin.uh.cu%2Fuser%2Fjose.vazquez%40iris.uh.cu&openid.sig=7pkT3Gn%2F%2BrWMyd8MIXFjKWqlrRpLQty%2BtGLdnPn3QJw%3D&openid.signed=claimed_id%2Cidentity%2Cassoc_handle%2Cop_endpoint%2Creturn_to%2Cresponse_nonce%2Cns.alias3%2Calias3.mode%2Calias3.type.alias1%2Calias3.value.alias1%2Calias3.type.alias2%2Calias3.value.alias2%2Calias3.type.alias3%2Calias3.value.alias3%2Calias3.type.alias4%2Calias3.value.alias4%2Calias3.type.alias5%2Calias3.value.alias5&openid.assoc_handle=%7B636110128883120000%7D%7B7CQalw%3D%3D%7D%7B32%7D&openid.op_endpoint=https%3A%2F%2Flogin.uh.cu%2Fopenid%2Fprovider&openid.return_to=http%3A%2F%2Flocalhost%3A10610%2Fopenid%3Fstate%3DCfDJ8AtrYQEuI5BNmfmQHh7HZDq2rbf8lzbXS_jQF3chWMa_usPliLwFiHrpOGjGkdFxYFUo5RSYUfq3eKOF1Lm1Pl7GOXbM5_pxeH0A79ULgoQmZ5xFoX8HYMWtZ-DiQfA4akr3qMcaXBE4vEr9gpjyoNFZCR5m3H_WBfqkGNUZKJUX63-g48NBdlUyVtz_jCJbrUWzKTbAntdF8ItBinWfHJL_Q8OFj8ygi1Gz9y7QXXmpPmWHZj2IGksfJnrPDt31Yg&openid.response_nonce=2016-10-03T14%3A41%3A24ZvBQT67JX&openid.mode=id_res&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.alias3=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.alias3.mode=fetch_response&openid.alias3.type.alias1=username&openid.alias3.value.alias1=jose.vazquez%40iris.uh.cu&openid.alias3.type.alias2=Apellido_1&openid.alias3.value.alias2=VAZQUEZ&openid.alias3.type.alias3=Apellido_2&openid.alias3.value.alias3=CALLEJAS&openid.alias3.type.alias4=role&openid.alias3.value.alias4=trabajador&openid.alias3.type.alias5=token&openid.alias3.value.alias5=0d01d266-1832-4b75-9f52-829f0f1d0338

@j2ghz j2ghz mentioned this issue Oct 4, 2016
@j2ghz
Copy link

j2ghz commented Oct 4, 2016

I moved my issue so it doesn't get mixed

@kevinchalet
Copy link
Member

@NachoVazquez the payload looks fine. If you're getting a blank page, make sure the CallbackPath setting is correct in the OpenID middleware options.

Note: only the claimed identifier will be automatically stored as a claim. To store the other values (e.g the role), you'll have to use the Authenticated event to add a custom claim:

app.UseOpenIdAuthentication(options => {
    // ...

    options.Events = new OpenIdAuthenticationEvents {
        OnAuthenticated = context => {
            string role;
            if (context.Attributes.TryGetValue("role", out role)) {
                context.Identity.AddClaim(new Claim(ClaimTypes.Role, role));
            }

            return Task.FromResult(0);
        }
    };
});

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants