# How to get current login username from onebox?

**URL:** https://meta.discourse.org/t/how-to-get-current-login-username-from-onebox/57061
**Category:** Development
**Created:** [2017年二月7日 13:45 UTC](https://meta.discourse.org/t/how-to-get-current-login-username-from-onebox/57061 "2017-02-07T13:45:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![suanfazu](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@suanfazu](https://meta.discourse.org/u/suanfazu)
#### Post date: [2017年二月7日 13:45 UTC](https://meta.discourse.org/t/how-to-get-current-login-username-from-onebox/57061/1 "2017-02-07T13:45:13Z")

</div>

I’m developing a plugin to embed jupyter notebooks into discourse posts. It’s a private jupyter server and the user can only share his notebooks. So i need to verify the user.

1. how to get the current user (and maybe the author of the post or reply) in discourse onebox plugin? i need to get the username (the login name)

2. another question is, there are script tags in notebook html? seems the onebox removes all the script tags. how to make it keep the script tags?

3. one more question, is there any cache in one box? seems there are no more requests when i modify and save the post

below is my test code

```
Onebox = Onebox

module Onebox
  module Engine
    class XXXXXXNotebookOnebox
      include Engine
      include JSON
      # include CurrentUser : NameError: uninitialized constant Onebox::Engine::BigQuantNotebookOnebox::CurrentUser
      # include CurrentUser

      matches_regexp(/^https?:\/\/i\.XXXXXXX\.com\/.+\.ipynb$/)

      def placeholder_html
        'hello place holder'
      end

      def to_html
        a = 'no user '
        if current_user
          a = 'has user'
        end
        "test hello html <iframe src='https://XXXXXX.com/'></iframe> <script>alert('test me');</script> end " + Time.new.inspect + a
      end
    end
  end
end

```

---

<div class="post-metadata">

### Author: ![joebuhlig](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/joebuhlig/32/193054_2.png) [@joebuhlig](https://meta.discourse.org/u/joebuhlig)
#### Post date: [2017年二月8日 22:57 UTC](https://meta.discourse.org/t/how-to-get-current-login-username-from-onebox/57061/2 "2017-02-08T22:57:23Z")

</div>

I may be wrong but I don’t think it’s possible to pull Discourse objects into the Onebox gem without requiring them as a dependency in some way. And even then, I’m not sure it’s a wise move. I think of Onebox as a separate entity that doesn’t require Discourse.

---

<div class="post-metadata">

### Author: ![suanfazu](https://avatars.discourse-cdn.com/v4/letter/s/f04885/32.png) [@suanfazu](https://meta.discourse.org/u/suanfazu)
#### Post date: [2017年二月9日 13:47 UTC](https://meta.discourse.org/t/how-to-get-current-login-username-from-onebox/57061/3 "2017-02-09T13:47:10Z")

</div>

thanks for the reply.

1. use [request\_store](https://rubygems.org/gems/request_store/), save user to request\_store in onebox controller
2. not found a solution, have to override the source (lib/onebox/discourse\_onebox\_sanitize\_config.rb) on rebuild
3. seems so, but it’s ok for me

---

<div class="post-metadata">

### Author: ![saulshanabrook](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saulshanabrook/32/292864_2.png) [@saulshanabrook](https://meta.discourse.org/u/saulshanabrook)
#### Post date: [2017年四月30日 22:47 UTC](https://meta.discourse.org/t/how-to-get-current-login-username-from-onebox/57061/4 "2017-04-30T22:47:38Z")

</div>

Did you ever develop this plugin? I am also interested in embedding Jupyter Notebooks into Discourse posts.
