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

Return token #246

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Return token #246

wants to merge 3 commits into from

Conversation

djedjethai
Copy link

Hi, I am using oauth2 as an authorization server to secure a microservices based app, doing like so I needed the *oauth2.Token to be returned as a payload(instead of being redirected), so I added 5 lines for(in /server/server.go).

type Server struct {
	Config                       *Config
	Manager                      oauth2.Manager
	..........
	IsModeAPI                    bool
}

func (s *Server) SetModeAPI() {
	s.IsModeAPI = true
}

func (s *Server) redirect(w http.ResponseWriter, req *AuthorizeRequest, data map[string]interface{}) error {
	if !s.IsModeAPI {
		uri, err := s.GetRedirectURI(req, data)
		if err != nil {
			return err
		}

		w.Header().Set("Location", uri)
		w.WriteHeader(302)
		return nil

	} else {
		w.Header().Set("Content-Type", "application/json")
		w.Header().Set("Cache-Control", "no-store")
		w.Header().Set("Pragma", "no-cache")

		w.WriteHeader(http.StatusOK)
		return json.NewEncoder(w).Encode(data)
	}
}

It does not create any breaking change, if you like it ?
As well I have given a simple but quite complet flow about a way to use it this way, in the /example/secureYourMicroservices, if you like it ? Wish you the best.

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

Successfully merging this pull request may close these issues.

2 participants