Coder Social home page Coder Social logo

cotacol-site's Introduction

Cotacol Web App

An attempt to learn Blazor, by setting up a Cotacol web site

This web site has been published to https://www.cotacol.eu and can be used to register and link your Strava profile against the Cotacol Hunting backend. This web site shares the same backend as the iOS app (and the Android app that is coming)

Troubleshooting & links

Identity login

  1. Set up razor server app, with individual identiy

  2. Scaffolded two pages, based on this article: https://andrewlock.net/customising-aspnetcore-identity-without-editing-the-pagemodel/

    • Account.Login, which enables the customization of the actual login page dotnet aspnet-codegenerator identity -dc CotacolApp.Data.ApplicationDbContext --files "Account.Login"
    • Account.ExternalLogin, which enables the customization of the actual strava page dotnet aspnet-codegenerator identity -dc CotacolApp.Data.ApplicationDbContext --files "Account.ExternalLogin"
  3. Add OAuth nuget package: Microsoft.AspNetCore.Authentication.OAuth

  4. Update Startup.cs to include Strava login

    services.AddAuthentication().AddOAuth("Strava",
        oAuthOptions =>
        {
            oAuthOptions.ClientId = "myappid"; 
            oAuthOptions.ClientSecret = "myclientsecret";
            oAuthOptions.Scope.Clear();        
            oAuthOptions.Scope.Add("read");
            oAuthOptions.CallbackPath = "/profile"; 
            oAuthOptions.AuthorizationEndpoint = "https://www.strava.com/oauth/authorize";
            oAuthOptions.TokenEndpoint = "https://www.strava.com/api/v3/oauth/token";
            oAuthOptions.SignInScheme = IdentityConstants.ExternalScheme;
            oAuthOptions.Events = new OAuthEvents()
            {
                OnRemoteFailure = loginFailureHandler =>
                {
                    Console.WriteLine("Remote Error");
                    Console.WriteLine(loginFailureHandler.Failure.Message);
                    return Task.FromResult(0);
                }, 
                OnAccessDenied = handler =>
                {
                    Console.WriteLine(handler.Response.StatusCode);
                    return Task.FromResult(0);
                }
            };
        });
  5. Issue when logging on : var info = await _signInManager.GetExternalLoginInfoAsync(); returns null. Similar issue found here : https://stackoverflow.com/questions/40227643/signinmanager-getexternallogininfoasync-always-returns-null-with-open-id-to-a

  6. Issue when getting null in GetExternalLoginInfoAsync : https://stackoverflow.com/questions/46158462/instagram-oauth-getexternallogininfoasync-always-returns-null-in-net-core-2-0/55970100

Access to tokens

It is important to get access to the OAuth Tokens, since they have to be passed to the API Backend, where they will be refreshed on a daily basis. The SaveTokens property does not seem to work, initially, so here are some posts/threads:

  1. Access tokens in asp.net core: https://blog.maartenballiauw.be/post/2020/01/13/making-api-calls-using-the-access-token-and-refresh-token-from-an-aspnet-core-authentication-handler.html

  2. https://docs.microsoft.com/en-us/aspnet/core/security/authentication/social/additional-claims?view=aspnetcore-5.0

InvalidOperationException: No authenticationScheme was specified, and there was no DefaultAuthenticateScheme found. The default schemes can be set using either AddAuthentication(string defaultScheme) or AddAuthentication(Action configureOptions).

cotacol-site's People

Contributors

samvanhoutte avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.