【问题标题】:Laravel Socialite initiate credentialsLaravel Socialite 发起凭证
【发布时间】:2015-03-17 14:24:56
【问题描述】:

我想将 Socialite 集成到基于 Laravel 的 CMS 中,我想弄清楚如果 client_id 和客户端密码保存在数据库中,我将如何启动 Socialite 发送请求?

来自文档基本用法

return Socialize::with('github')->redirect();

并且凭据保存在 config/services.php 中

/**
 * Create an instance of the specified driver.
 *
 * @return \Laravel\Socialite\Two\AbstractProvider
 */
protected function createGithubDriver()
{
    $config = $this->app['config']['services.github'];

    return $this->buildProvider(
        'Laravel\Socialite\Two\GithubProvider', $config
    );
}

我想在工厂调用中定义 $this->app['config']

【问题讨论】:

  • 您应该能够扩展createGithubDriver() 方法以从数据库中提取内容
  • 或者您可以在应用程序的其他位置放置一些逻辑,以便在调用此函数之前设置配置值
  • 是的,最后一个将是完美的解决方法,仍在努力解决
  • 尝试将逻辑添加到自定义服务提供者的引导方法中,这可能有效(Laravel 5)
  • 使用.evn文件存储这些信息不是更好吗,我觉得这样更安全。 (env 文件是作为 laravel 5 的一部分引入的)

标签: laravel oauth-2.0


【解决方案1】:

你能不能只创建一个中间件类,将它应用到相关路由,然后使用以下方法设置配置:

$v = Auth::user()->github // or however you work it out, not sure how you've got it stored
Config::set('services.github', $v);

像这样设置配置只为当前请求设置它

【讨论】:

    猜你喜欢
    • 2016-07-11
    • 2016-06-28
    • 2020-07-07
    • 1970-01-01
    • 2016-06-02
    • 2018-03-22
    • 2018-01-02
    • 2016-09-01
    • 2023-02-08
    相关资源
    最近更新 更多