You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I wanted to get some examples of how to add login authentication. I have some ideas myself, but curious what the world has in mind.
Describe the solution you'd like
I would like to see examples for:
Firebase auth
3rd party Auth
perhaps some JWT and or cookie solutions
The text was updated successfully, but these errors were encountered:
@vinceyoumans Login/authentication would depend on what service you're using. You've mentioned Firebase, JWT etc. In case of Webgo, the middleware is quite easy to write. I use the following:
funcAuthenticateAndAuthorize(rw http.ResponseWriter, req*http.Request, next http.HandlerFunc) {
wctx:=webgo.Context(r)
// I use webgo's route.Name to identify a route/API. e.g. 'getusers', 'myapp.users.get' etc.// The same name can be given for multiple routes if your app needs it.currentAPI:=wctx.Route.Name// openAPIs is a slice of strings, which are open for any user. i.e. no authentication requiredfor_, oapi:=rangeopenAPIs {
ifoapi==currentAPI {
next(rw, req)
return
}
}
// there might be some APIs which need not have specific access, but only requires the user to be// authenticated. Those for_, authAPI:=rangeauthOnlyAPIs {
ifcurrentAPI==authAPI {
next(rw, req)
return
}
}
// sess is a session instance (there's no code posted for this), which I'm using from a custom IAM (within my company)// It makes sure if the user has access to the respective APIerr:=sess.IsAuthorized(currentAPI)
iferr==nil {
next(rw, req)
return
}
// if user is trying to access an unauthorized API, a security log is generated.// `logH` is an instance of the logger I uselogH.Security(
err.Error(),
sess.ClientID,
sess.OrganizationID,
req.RemoteAddr,
req.URL.String(),
)
// errors is a custom errors package which I use, github.com/bnkamalesh/errorsstatus, msg, _:=errors.HTTPStatusCodeMessage(err)
webgo.SendError(rw, msg, status)
}
The above is a sample of a middleware which implements authentication + authorization. And it can be used as follows:
Is your feature request related to a problem? Please describe.
I wanted to get some examples of how to add login authentication. I have some ideas myself, but curious what the world has in mind.
Describe the solution you'd like
I would like to see examples for:
Firebase auth
3rd party Auth
perhaps some JWT and or cookie solutions
The text was updated successfully, but these errors were encountered: