ronzeidman / ng2-ui-auth

an angular2 repository for authentication based on angular1's satellizer
MIT License
206 stars 64 forks source link

POST method for authorizationEndpoint #141

Closed Alenorze closed 6 years ago

Alenorze commented 6 years ago
Ng2UiAuthModule.forRoot({providers: {linkedin: {clientId: '86cpqsfsmi7ej5j', url: 'http://localhost:8000/api/login/social/session/linkedin-oauth2', redirectUri: 'http://localhost:8000'}}}),

I have an implementation example, but with the same parameters it does not work here

    angular.module('SessionApp', ['satellizer'])
          .config(function($authProvider) {
            $authProvider.linkedin({
              url: "{% url 'login_social_session' provider='linkedin-oauth2' %}",
              clientId: '86cpqssmi7ej5j',
              redirectUri: window.location.origin + '/'
            });

          }).config(function($httpProvider) {
              $httpProvider.defaults.xsrfCookieName = 'csrftoken';
              $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
          }).controller('LoginCtrl', function($scope, $auth, $http) {
            self = this;
            self.user = {};
            set_user();
            var req = {
                method: "GET",
                url: '{% url "current_user_session" %}',
                skipAuthorization: true  // in case of session auth don't send token header
            }
            $http(req).then(function(response){
                console.log("Got user from session cookies");
                set_user(response);
                console.log(response);
            });
            $scope.authenticate = function(provider) {
                $auth.authenticate(provider).then(set_user);
            };
            $scope.logout = function(){
                var req = {
                    method: "POST",
                    url: '{% url "logout_session" %}',
                    skipAuthorization: true  // in case of session auth don't send token header
                }
                $http(req).then(function(response){
                    set_user();
                });
            };
        });
ronzeidman commented 6 years ago

maybe you have to add a '/' to your redirectUri? (redirectUri: 'http://localhost:8000/') the default method is 'POST' you can change it by specifying method: 'GET' in the provider setup

Alenorze commented 6 years ago

I solved this problem, slightly confused