// Create API-specific OAuth handlers and respective auth servers func addOAuthHandlers(spec *APISpec, Muxer *mux.Router, test bool) *OAuthManager { apiAuthorizePath := spec.Proxy.ListenPath + "tyk/oauth/authorize-client/" clientAuthPath := spec.Proxy.ListenPath + "oauth/authorize/" clientAccessPath := spec.Proxy.ListenPath + "oauth/token/" serverConfig := osin.NewServerConfig() serverConfig.ErrorStatusCode = 403 serverConfig.AllowedAccessTypes = spec.Oauth2Meta.AllowedAccessTypes serverConfig.AllowedAuthorizeTypes = spec.Oauth2Meta.AllowedAuthorizeTypes OAuthPrefix := generateOAuthPrefix(spec.APIID) //storageManager := RedisClusterStorageManager{KeyPrefix: OAuthPrefix} storageManager := GetGlobalStorageHandler(OAuthPrefix, false) storageManager.Connect() osinStorage := RedisOsinStorageInterface{storageManager, spec.SessionManager} //TODO: Needs storage manager from APISpec if test { log.WithFields(logrus.Fields{ "prefix": "main", }).Warning("Adding test clients") testPolicy := Policy{} testPolicy.Rate = 100 testPolicy.Per = 1 testPolicy.QuotaMax = -1 testPolicy.QuotaRenewalRate = 1000000000 Policies["TEST-4321"] = testPolicy testClient := OAuthClient{ ClientID: "1234", ClientSecret: "aabbccdd", ClientRedirectURI: "http://client.oauth.com", PolicyID: "TEST-4321", } osinStorage.SetClient(testClient.ClientID, &testClient, false) log.WithFields(logrus.Fields{ "prefix": "main", }).Warning("Test client added") } osinServer := TykOsinNewServer(serverConfig, osinStorage) // osinServer.AccessTokenGen = &AccessTokenGenTyk{} oauthManager := OAuthManager{spec, osinServer} oauthHandlers := OAuthHandlers{oauthManager} Muxer.HandleFunc(apiAuthorizePath, CheckIsAPIOwner(oauthHandlers.HandleGenerateAuthCodeData)) Muxer.HandleFunc(clientAuthPath, oauthHandlers.HandleAuthorizePassthrough) Muxer.HandleFunc(clientAccessPath, oauthHandlers.HandleAccessRequest) return &oauthManager }
// Create API-specific OAuth handlers and respective auth servers func addOAuthHandlers(spec *APISpec, Muxer *mux.Router, test bool) *OAuthManager { apiAuthorizePath := spec.Proxy.ListenPath + "tyk/oauth/authorize-client/" clientAuthPath := spec.Proxy.ListenPath + "oauth/authorize/" clientAccessPath := spec.Proxy.ListenPath + "oauth/token/" serverConfig := osin.NewServerConfig() serverConfig.ErrorStatusCode = 403 serverConfig.AllowedAccessTypes = spec.Oauth2Meta.AllowedAccessTypes serverConfig.AllowedAuthorizeTypes = spec.Oauth2Meta.AllowedAuthorizeTypes OAuthPrefix := OAUTH_PREFIX + spec.APIID + "." //storageManager := RedisClusterStorageManager{KeyPrefix: OAuthPrefix} storageManager := GetGlobalStorageHandler(OAuthPrefix, false) storageManager.Connect() osinStorage := RedisOsinStorageInterface{storageManager, spec.SessionManager} //TODO: Needs storage manager from APISpec if test { log.WithFields(logrus.Fields{ "prefix": "main", }).Warning("Adding test client") testClient := osin.DefaultClient{ Id: "1234", Secret: "aabbccdd", RedirectUri: "http://client.oauth.com", } osinStorage.SetClient(testClient.Id, &testClient, false) log.WithFields(logrus.Fields{ "prefix": "main", }).Warning("Test client added") } osinServer := TykOsinNewServer(serverConfig, osinStorage) // osinServer.AccessTokenGen = &AccessTokenGenTyk{} oauthManager := OAuthManager{spec, osinServer} oauthHandlers := OAuthHandlers{oauthManager} Muxer.HandleFunc(apiAuthorizePath, CheckIsAPIOwner(oauthHandlers.HandleGenerateAuthCodeData)) Muxer.HandleFunc(clientAuthPath, oauthHandlers.HandleAuthorizePassthrough) Muxer.HandleFunc(clientAccessPath, oauthHandlers.HandleAccessRequest) return &oauthManager }