func SignInOAuth(ctx *context.Context) {
	provider := ctx.Params(":provider")

	loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
	if err != nil {
		ctx.ServerError("SignIn", err)
		return
	}

	// try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user
	user, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req, ctx.Resp)
	if err == nil && user != nil {
		// we got the user without going through the whole OAuth2 authentication flow again
		handleOAuth2SignIn(ctx, user, gothUser)
		return
	}

	if err = oauth2.Auth(loginSource.Name, ctx.Req, ctx.Resp); err != nil {
		if strings.Contains(err.Error(), "no provider for ") {
			if err = models.ResetOAuth2(); err != nil {
				ctx.ServerError("SignIn", err)
				return
			}
			if err = oauth2.Auth(loginSource.Name, ctx.Req, ctx.Resp); err != nil {
				ctx.ServerError("SignIn", err)
			}
			return
		}
		ctx.ServerError("SignIn", err)
	}
	// redirect is done in oauth2.Auth
}
// SignInOAuth handles the OAuth2 login buttons
SignInOAuth handles the OAuth2 login buttons
// SignInOAuth handles the OAuth2 login buttons
func SignInOAuth(ctx *context.Context) {
	provider := ctx.Params(":provider")
	loginSource, err := models.GetActiveOAuth2LoginSourceByName(provider)
	if err != nil {
		ctx.ServerError("SignIn", err)
		return
	}
	user, gothUser, err := oAuth2UserLoginCallback(loginSource, ctx.Req, ctx.Resp)
	if err == nil && user != nil {
		handleOAuth2SignIn(ctx, user, gothUser)
		return
	}
	if err = oauth2.Auth(loginSource.Name, ctx.Req, ctx.Resp); err != nil {
		if strings.Contains(err.Error(), "no provider for ") {
			if err = models.ResetOAuth2(); err != nil {
				ctx.ServerError("SignIn", err)
				return
			}
			if err = oauth2.Auth(loginSource.Name, ctx.Req, ctx.Resp); err != nil {
				ctx.ServerError("SignIn", err)
			}
			return
		}
		ctx.ServerError("SignIn", err)
	}
}
func SignInOAuth ( ctx * context . Context ) { provider := ctx . Params ( " " ) loginSource , err := models . GetActiveOAuth2LoginSourceByName ( provider ) if err != nil { ctx . ServerError ( " " , err ) return } user , gothUser , err := oAuth2UserLoginCallback ( loginSource , ctx . Req , ctx . Resp ) if err == nil && user != nil { handleOAuth2SignIn ( ctx , user , gothUser ) return } if err = oauth2 . Auth ( loginSource . Name , ctx . Req , ctx . Resp ) ; err != nil { if strings . Contains ( err . Error ( ) , " " ) { if err = models . ResetOAuth2 ( ) ; err != nil { ctx . ServerError ( " " , err ) return } if err = oauth2 . Auth ( loginSource . Name , ctx . Req , ctx . Resp ) ; err != nil { ctx . ServerError ( " " , err ) } return } ctx . ServerError ( " " , err ) } }
SignInOAuth handles the OAuth2 login buttons
SignInOAuth handles the OAuth2 login buttons
// try to do a direct callback flow, so we don't authenticate the user again but use the valid accesstoken to get the user // we got the user without going through the whole OAuth2 authentication flow again // redirect is done in oauth2.Auth