auth
2014-08-16
Parent:7a6f64db7246
auth/README.md
Implement CSRF prevention and pass info to confirmation. Implement CSRF prevention using the nosurf package. Note that the handler still needs to be wrapped before this will work. Pass info on the authorization being requested (namely the client and the scope) to the RenderConfirmation page so that the user can make an educated decision.
| paddy@0 | 1 OSIN |
| paddy@0 | 2 ==== |
| paddy@0 | 3 |
| paddy@0 | 4 Golang OAuth2 server library |
| paddy@0 | 5 ---------------------------- |
| paddy@0 | 6 |
| paddy@0 | 7 OSIN is an OAuth2 server library for the Go language, as specified at |
| paddy@0 | 8 http://tools.ietf.org/html/rfc6749 and http://tools.ietf.org/html/draft-ietf-oauth-v2-10. |
| paddy@0 | 9 |
| paddy@0 | 10 Using it, you can build your own OAuth2 authentication service. |
| paddy@0 | 11 |
| paddy@0 | 12 The library implements the majority of the specification, like authorization and token endpoints, and authorization code, implicit, resource owner and client credentials grant types. |
| paddy@0 | 13 |
| paddy@0 | 14 ### Dependencies |
| paddy@0 | 15 |
| paddy@0 | 16 * go-uuid (http://code.google.com/p/go-uuid) |
| paddy@0 | 17 |
| paddy@0 | 18 ### Example Server |
| paddy@0 | 19 |
| paddy@0 | 20 ````go |
| paddy@0 | 21 import "github.com/RangelReale/osin" |
| paddy@0 | 22 |
| paddy@0 | 23 // TestStorage implements the "osin.Storage" interface |
| paddy@0 | 24 server := osin.NewServer(osin.NewServerConfig(), &TestStorage{}) |
| paddy@0 | 25 |
| paddy@0 | 26 // Authorization code endpoint |
| paddy@0 | 27 http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) { |
| paddy@0 | 28 resp := server.NewResponse() |
| paddy@0 | 29 if ar := server.HandleAuthorizeRequest(resp, r); ar != nil { |
| paddy@0 | 30 |
| paddy@0 | 31 // HANDLE LOGIN PAGE HERE |
| paddy@0 | 32 |
| paddy@0 | 33 ar.Authorized = true |
| paddy@0 | 34 server.FinishAuthorizeRequest(resp, r, ar) |
| paddy@0 | 35 } |
| paddy@0 | 36 osin.OutputJSON(resp, w, r) |
| paddy@0 | 37 }) |
| paddy@0 | 38 |
| paddy@0 | 39 // Access token endpoint |
| paddy@0 | 40 http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) { |
| paddy@0 | 41 resp := server.NewResponse() |
| paddy@0 | 42 if ar := server.HandleAccessRequest(resp, r); ar != nil { |
| paddy@0 | 43 ar.Authorized = true |
| paddy@0 | 44 server.FinishAccessRequest(resp, r, ar) |
| paddy@0 | 45 } |
| paddy@0 | 46 osin.OutputJSON(resp, w, r) |
| paddy@0 | 47 }) |
| paddy@0 | 48 |
| paddy@0 | 49 http.ListenAndServe(":14000", nil) |
| paddy@0 | 50 ```` |
| paddy@0 | 51 |
| paddy@0 | 52 ### Example Access |
| paddy@0 | 53 |
| paddy@0 | 54 Open in your web browser: |
| paddy@0 | 55 |
| paddy@0 | 56 ```` |
| paddy@0 | 57 http://localhost:14000/authorize?response_type=code&client_id=1234&redirect_url=http%3A%2F%2Flocalhost%3A14000%2Fappauth%2Fcode |
| paddy@0 | 58 ```` |
| paddy@0 | 59 |
| paddy@0 | 60 ### License |
| paddy@0 | 61 |
| paddy@0 | 62 The code is licensed using "New BSD" license. |
| paddy@0 | 63 |
| paddy@0 | 64 ### Author |
| paddy@0 | 65 |
| paddy@0 | 66 Rangel Reale |